Re: Problems with Constructor Methods
From: Hal Rosser (hmrosser_at_bellsouth.net)
Date: 11/27/04
- Next message: Anonymous: "Image recreated even after deletion by java."
- Previous message: Andrew Thompson: "Re: ????? instead of cyrilic letters"
- In reply to: JS: "Problems with Constructor Methods"
- Next in thread: JS: "Re: Problems with Constructor Methods"
- Reply: JS: "Re: Problems with Constructor Methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 26 Nov 2004 22:50:03 -0500
"JS" <dsa.@asdf.com> wrote in message news:co8iu3$noa$1@news.net.uni-c.dk...
> This code works:
>
> import javax.swing.*;
> public class HelperClass
> {
> public void computeSquareRoot()
> { String s = JOptionPane.showInputDialog("Type a number:");
> double d = new Double(s).doubleValue();
> double root = Math.sqrt(d);
> JOptionPane.showMessageDialog(null,
> "The square root of " + d + " is " + root);
> }
> }
>
> class test
> {public static void main(String[] args)
> {HelperClass writer = new HelperClass();
> writer.computeSquareRoot();
>
> }}
>
> But I am trying to make another which calculates the length of two names
and
> show the names and their length in a dialog windows. But I can't get it to
> work:
>
> class NameLength
> { public static void main(String[] args)
> { HelperClass c = new HelperClass();
> c.readNameAndDisplayItsLength();
> c.readNameAndDisplayItsLength();
> JOptionPane.showMessageDialog(null, "Finished!");
> }}
>
>
> class HelperClass
> {
> public void readNameAndDisplayItsLength()
> { String a = JOptionPane.showInputDialog("Type a name:");
> int z = a.length();
> JOptionPane.showMessageDialog(null, a + " Length is " + z);
> }
> }
>
>
> I guess class test and class NameLength has the same function. But why
then
> has NameLength the line JOptionPane.showMessageDialog(null,
> "Finished!");
>
> And why does it have two c.readNameAndDisplayItsLength();
>
> When i write: java NameLength I get the following error:
>
> NoSuchMethodError: HelperClass.readNameAndDisplayItsLength()V
> at NameLength.main(Johannes_Serup_48.java:149)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
>
without looking at the whole thing -
it appears you have 2 classes with the same name (HelperClass) - I stopped
at that point
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.799 / Virus Database: 543 - Release Date: 11/19/2004
- Next message: Anonymous: "Image recreated even after deletion by java."
- Previous message: Andrew Thompson: "Re: ????? instead of cyrilic letters"
- In reply to: JS: "Problems with Constructor Methods"
- Next in thread: JS: "Re: Problems with Constructor Methods"
- Reply: JS: "Re: Problems with Constructor Methods"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|