• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error

 
sakshi sa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai all,
when i run the program,i got Exception in thread main java.lang.NoSuchMethod Error.
could you please tell me what is the meaning of this.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseAMeaningfulSubjectLine next time.

That means that the class doesn't contain the method. It usually happens when you use the wrong version of a certain library.
Try updating and checking your dependencies.
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also please post the Code you are trying to execute.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked in the API documentation?
 
sakshi sa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all, i execute the program.

 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be of tremendous help if you posted the exact error you get when you run your code. It makes it easier for dumb people like me to zero in on where the problem is, without having to copy your code, paste it into a document, compile it, and run it (which is what I did).

Once I did that, I saw this error:
Exception in thread "main" java.lang.NoSuchMethodError: main

Seeing that tells me there is a problem with your main method.

Now I know exactly where to look. The main method in this code looks like this:



When you start a java program, it is looking for a main with a signiature of this:



If you simply put in that argument to your main method, the code will run.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the record, here is the code you originally posted, then deleted:

 
Campbell Ritchie
Sheriff
Pie
Posts: 50278
80
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not quite sure how Fred found the code you deleted; maybe he was just there in the 5 minutes it was visible. That example shows how bad it can be to delete old posts or parts of them; the remainder of the thread reads like nonsense.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see how comments such as:
// Instance data
// Constructor
// Accessor

help to clarify the code. The fact that it is an instance variable/constructor/getter is made clear by the definition of it. You don't need the comment at all. In fact now you have 2 parts to change if you want to change something. The method definition and the comment. If you forget to change one then voila: confusion.

I can somewhat understand the following comment:
// Implementations of abstract methods.
But Java contains a special annotation for that: @Override. It even has a bonus. If the method doesn't override/implement a method then the compiler will complain.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic