hi all! i have a doubt on page 78 RHE (new edition chapter3(Modifiers).the programme can be compiled but giving a run time error as "NoSuchMethodError" can some one help me please?
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5781
posted
0
Since many may not have the new edition of RHE, how about posting the code here?? Ajith
Open Group Certified Master IT Architect.
Sun Certified Architect(SCEA).
nachiket deshpande
Ranch Hand
Joined: Oct 06, 2000
Posts: 114
posted
0
the code is---- class complex{ private double real,imaginary; public complex(double r,double imaginary);{ real=r,imaginary=i; } public complex add(complex c){ return new complex(real + c.real,imaginary + c.imaginary); } } class client{ public static void main(String args[]){ complex c1=new complex(1,2); complex c2=new complex(3,4); complex c3=c1.add(c2); } } the error is "NoSuchMethodError" in "main".(at run time )
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5781
posted
0
What have you named the source file?? Since the main method is declared in the "client" class, you should name the source file as client.java Notwithstanding various typos you have in your code, it runs just fine when saved in client.java. Here's the error-free source code -
Ajith
lakshmi nair
Ranch Hand
Joined: Oct 11, 2000
Posts: 63
posted
0
There were some typos in your code. But altogether it works fine. I have changed your code slightly.
HTH Lakshmi
nachiket deshpande
Ranch Hand
Joined: Oct 06, 2000
Posts: 114
posted
0
sorry... i did store it in wrong file thanks
Carol Enderlin
drifter
Ranch Hand
Joined: Oct 10, 2000
Posts: 1340
posted
0
I had success saving in file complex.java and compiling "javac complex.java", but need to run with "java client" and not "java complex" as shown below (compiling Ajith's code): >javac complex.java >java complex Exception in thread "main" java.lang.NoSuchMethodError: main >java client 4.0 +i 6.0