 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
keith vescovo via JavaKB. Guest
|
Posted: Wed Apr 27, 2005 2:39 pm Post subject: "Exception in thread "main" java.lang.nosuchmethodError: mai |
|
|
I keep getting this message when trying to run a java program that
calculates the hypotenuse of a right triangle. The program will compile,
but it won't run. Could someone please help me with this? Any help will
be greatly appreciated. Here is the code for my program:
// Exercise 6.15 Solution
// Triangle.java
// Program calculates the hypotenuse of a right triangle.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Triangle extends JApplet implements ActionListener
{
JTextField sideInput, side2Input;
JLabel sidePrompt, sidePrompt2;
public void init()
{
sideInput = new JTextField( 4 );
side2Input = new JTextField( 4 );
side2Input.addActionListener( this );
sidePrompt = new JLabel( "Enter side 1: " );
sidePrompt2 = new JLabel( "Enter side 2: " );
Container c = getContentPane();
c.setLayout( new FlowLayout() );
c.add( sidePrompt );
c.add( sideInput );
c.add( sidePrompt2 );
c.add( side2Input );
}
public void actionPerformed( ActionEvent e )
{
double sidel, side2;
sidel = Double.parseDouble( side2Input.getText() );
side2 = Double.parseDouble( sideInput.getText() );
double h = hypotenuse( sidel, side2 );
showStatus( "Hypotenuse is : " + h );
}
public double hypotenuse( double side1, double side2 )
{
double hypotSquared = Math.pow( side1, 2 ) + Math.pow( side2,
2 );
return Math.sqrt( hypotSquared );
}
}
|
|
| Back to top |
|
 |
Fred L. Kleinschmidt Guest
|
Posted: Wed Apr 27, 2005 3:46 pm Post subject: Re: "Exception in thread "main" java.lang.nosuchmethodError: |
|
|
"keith vescovo via JavaKB.com" wrote:
| Quote: |
I keep getting this message when trying to run a java program that
calculates the hypotenuse of a right triangle. The program will compile,
but it won't run. Could someone please help me with this? Any help will
be greatly appreciated. Here is the code for my program:
// Exercise 6.15 Solution
// Triangle.java
// Program calculates the hypotenuse of a right triangle.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Triangle extends JApplet implements ActionListener
{
JTextField sideInput, side2Input;
JLabel sidePrompt, sidePrompt2;
public void init()
{
sideInput = new JTextField( 4 );
side2Input = new JTextField( 4 );
side2Input.addActionListener( this );
sidePrompt = new JLabel( "Enter side 1: " );
sidePrompt2 = new JLabel( "Enter side 2: " );
Container c = getContentPane();
c.setLayout( new FlowLayout() );
c.add( sidePrompt );
c.add( sideInput );
c.add( sidePrompt2 );
c.add( side2Input );
}
public void actionPerformed( ActionEvent e )
{
double sidel, side2;
sidel = Double.parseDouble( side2Input.getText() );
side2 = Double.parseDouble( sideInput.getText() );
double h = hypotenuse( sidel, side2 );
showStatus( "Hypotenuse is : " + h );
}
public double hypotenuse( double side1, double side2 )
{
double hypotSquared = Math.pow( side1, 2 ) + Math.pow( side2,
2 );
return Math.sqrt( hypotSquared );
}
}
|
Well, did you pay attention to the error message? What does it say? It
says it can't find the method called "main". And, sure enough, it has no
"main" method. It also has no constructor.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
#! rnews 1516
Xref: xyzzy sci.energy:129135 sci.energy.hydrogen:80008 sci.environment:392656
Newsgroups: sci.environment,sci.energy.hydrogen,sci.energy
Path: xyzzy!nntp
From: "Fred McGalliard" <frederick.b.mcgalliard (AT) boeing (DOT) com>
Subject: Re: Iceland's Hydrogen Buses Zip Toward Oil-Free Economy
X-Nntp-Posting-Host: e056750.nw.nos.boeing.com
Message-ID: <IFM40L.Lyu (AT) news (DOT) boeing.com>
X-Mimeole: Produced By Microsoft MimeOLE V6.00.2800.1409
X-Priority: 3
X-Msmail-Priority: Normal
Lines: 12
Sender: [email]nntp (AT) news (DOT) boeing.com[/email] (Boeing NNTP News Access)
Organization: The Boeing Company
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
References: <1113801303.308367.47350 (AT) o13g2000cwo (DOT) googlegroups.com> <c7f3c$42666fdf$42a7d082$28048 (AT) msgid (DOT) meganewsservers.com> <1114097074.642427.144360 (AT) z14g2000cwz (DOT) googlegroups.com> <78586$42683031$42a7d082$14712 (AT) msgid (DOT) meganewsservers.com> <3cqt0oF6ohjc3U1 (AT) individual (DOT) net> <1114308069.316432.37860 (AT) f14g2000cwb (DOT) googlegroups.com> <3d0epaF6rdd9lU1 (AT) individual (DOT) net> <1114471821.827590.301540 (AT) o13g2000cwo (DOT) googlegroups.com> <3d5e59F6qmqh3U1 (AT) individual (DOT) net> <1114485934.822772.76900 (AT) l41g2000cwc (DOT) googlegro
Date: Wed, 27 Apr 2005 15:50:44 GMT
"Don Lancaster"
....
| Quote: | The point the troll missed is that my consulting services offer accurate
and unbiased research into physical, engineering, and most especially
thermodynamic limits.
|
Don. You need to be careful about claiming expertise you do not have in
thermo.
|
|
| Back to top |
|
 |
keith vescovo via JavaKB. Guest
|
Posted: Wed Apr 27, 2005 5:33 pm Post subject: Re: "Exception in thread "main" java.lang.nosuchmethodError: |
|
|
Peter,
Thank you so much for your help. As you can see, I'm a novice in Java
programming. Thanks for being so courteous and understanding. I followed
your instructions, and my program worked perfectly.
Thanks Again,
Keith
--
Message posted via http://www.javakb.com
|
|
| Back to top |
|
 |
keith vescovo via JavaKB. Guest
|
Posted: Wed Apr 27, 2005 5:57 pm Post subject: Re: "Exception in thread "main" java.lang.nosuchmethodError: |
|
|
As you can see, I'm quite the novice in Java programming, but I'm learning
more every day. I came to this site to seek help from knowledgeable people
who are eager to help the beginner. Obviously you are not one of these
people that I seek. However, I did get a courteous and excellent reply
from someone. If all you are going to do is send insulting replies, then
why do you even bother to answer? Thanks for nothing, and have a great day.
Keith
--
Message posted via http://www.javakb.com
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|