• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in RHE page 78(new edition)

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since many may not have the new edition of RHE, how about posting the code here??
Ajith
 
nachiket deshpande
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There were some typos in your code. But altogether it works fine.
I have changed your code slightly.

HTH
Lakshmi
 
nachiket deshpande
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry...
i did store it in wrong file
thanks
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic