File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in RHE page 78(new edition) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in RHE page 78(new edition)" Watch "Doubt in RHE page 78(new edition)" New topic
Author

Doubt in RHE page 78(new edition)

nachiket deshpande
Ranch Hand

Joined: Oct 06, 2000
Posts: 114
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: 5782
Since many may not have the new edition of RHE, how about posting the code here??
Ajith


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
nachiket deshpande
Ranch Hand

Joined: Oct 06, 2000
Posts: 114
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: 5782
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
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
sorry...
i did store it in wrong file
thanks
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in RHE page 78(new edition)
 
Similar Threads
a doubt
Doubt with JSTL
doubt
string doubt
DOUBT!!