• Post Reply Bookmark Topic Watch Topic
  • New Topic

Intermittent: "Exception in thread main Java.lang.NoSuchMethodError"  RSS feed

 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I am using NetBeans under Windows.

I am comfortable with Java but new to GUIs, and that is my assignment.
I am writing a series of mini-games where the user can go back and forth between games, taking their score with them.

I was playing with my program...testing it. It was working fine. Having fun with it.
I exited the program and hit 'Play' in NetBeans - and I got the error "Exception in thread main Java.lang.NoSuchMethodError".
To be clear, there were no code changes in between the successful run and the failed run. I double checked my files in case of an accidental change and there weren't any.

I tried it over and over again, after all, it showed up out of nowhere - maybe it would just go away :-)

It did, eventually, but not until I stepped into the code and through nearly all of the code in the debugger.
I exited the debugger and just hit 'Play' again and it worked fine. It has worked since.

I have to demo this program. I can't have it fail in front of everyone when I hit 'Play'.

Does anyone know if this could be an installation issue, a missing or bad library, a missing path...anything?

any help is greatly appreciated.

 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anne,

Welcome to CodeRanch!

As I'm not much aware of NetBeans IDE, I'm not sure about what exactly does 'play' button do (does it run the code?).

Also, when you got NoSuchMethodError - for what method you got it? Was it main method or something else? But then again, not sure how it worked second time (maybe auto-compile was toggled?).

Anyways, regarding the demo - the most sure-shot way to get your demo right is:
1) Get rid of IDE (unless you want to present demo about IDE + code)
2) Create executable jar (we also have options to package all dependent jars/classes in it - to avoid lengthy classpath at runtime). Also make sure you have main class defined in manifest file.
3) Run the code with

I hope this helps.

If you feel the issue is specific to NetBeans and not Java, then we have dedicated forum here(<-click)
 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anayonkar, thanks for the quick response...And here I thought I was so very clear in my post!

I am required to use NetBeans IDE. Ugh The 'Play' button is just a run-button

>> for what method you got it
The error was just as posted - for "main" thread but as I said, this is code I was running just running, exited the run and re-started the run and with no changes in between, and it failed!

Sometimes in VS for C++, a project can get "corrupted". There is a file in the debug folder...if memory serves, it is the .plg file...and when that file gets too large, compiles are incomplete, for lack of a better work. Programs can produce odd and unpredictable results. It doesn't happen often but it does happen. anyway, the answer is...delete the .plg file, re-build the world, and all is OK. But the advantage is, once you have your executable, there cannot be a any problems. Here I have to 'run' to start my demo.

Could there be something like that going on?
 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're getting that error then there should be a proper stack trace somewhere which should point you to where the error is occurring.
Without that then we'll just be guessing.
 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, I appreciate the response but what I am asking is if anyone has witnessed Java having the same "issue" as C++ can have in Visual Studio? Or, if someone else has had a similar experience where their Java program become 'corrupt' after it was clearly working (and without changes in between a good run and the failed run).

I didn't mention this but I am able to read a stack dump and the file/method that it is telling me is missing, isn't.

Often it happens people have the same experiences and they can say, 'Yes, that happened to me when..."
That is what I am looking for. I haven't posted code so I am sure it would be nearly impossible for someone here to actually solve the problem for me, which I am not even asking. Just looking for clues.

If I sound snippy...not trying to be at all. Just in a hurry to leave for work. Your help/clues are **greatly** appreciated.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I've seen it every now and then, but I usually get a NoClassDefFoundError. A "Clean and Build" before running usually solves it.

You can try enabling "Compile on Save", from "Build > Compiling" in your project properties.
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anne Marie wrote:. . . if anyone has witnessed Java having the same "issue" as C++ can have in Visual Studio? . . .
Forget all about C++; Java® is a different language and behaves differently.

Did you have any red marks against the code to show compilation errors? If so, fix the errors first. You cannot expect non‑compiling code to run, but the IDE will have a good try and the no such method error is its last gasp telling you it can't manage it.

Another reason for not using IDEs at an early stage.

Yes, it is possible for .class files to become corrupt. It usually means a dependency has been recompiled and corrupted and the requisite method has gone walkies. You can see that if you read the documentation for that particular exception.
 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for responses:

Campbell Ritchie: I am not comparing C++ and Java. I was using as a brainstorming activity...an analogy...an example...to find out [/i]how it behave differently[/i]. I completely understand Java is a different language. I agree with not using the IDE but it is part of the assignment.

Stephan va Hulst: A "Clean and Build" before running usually solves it. - at least for my demo, that is a good point...though I really do want to understand how this happens.

This is very weird because there were no compile errors whatsoever. This was purely runtime.


 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way this turns up is dependency issues. That is, multiple versions of some dependency on the runtime path.
You compile against one version (the one with method 'a'), so no compilation problem, however whatever dependency manager you;re using has pulled in an earlier version of the library.
At runtime it can be hit or miss as to whether it picks up the class with the method in question, or the earlier version without it.
 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave, thanks so much. I will look into it.

If anyone else has suggestions, I will accept them too!

Andrea

 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is probably in a .class file, and there may be nothing wrong with any .java files. If Clean and Build solves the problem it might be a two‑version problem as DT suggested.

And welcome to the Ranch again
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you managing your dependencies? You need to make sure you don't have multiple versions of the same library in your classpath. Intermittent Classloader problems (they usually show up as NoClassDefFoundError or No SuchMethodError) are usually because of this. I would look at the class that it's complaining about and try to see if the class is in multiple jar files

Since, you are familiar with C++ you are probably familiar with the term DLL hell. This happens when 2 versions of the same DLL are in Path. Sometimes the application picks one, sometimes the other, which results in intermittent problems. This is Java's version of DLL Hell, which I call Jar Hell. You have 2 versions of the Jar in your classpath, and sometimes it picks one and sometimes the other. Which one it picks depends on many factors, including but not limited to a) what you have done before b) which house Mars is in, and c) how many crows are flying over New York
 
Anne Marie
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still trying to figure this out but want to mention something else...

The structure of my class is this:

Public class myGUI extends JPanel
A list of private attributes
A constructor
Several helper functions
Three ActionListener implementations
One for a menu button, one for a spin button, and one for a score report button

Every button works and i have no compile errors. However, when i am looking in my IDE, the IDE highlights the last line of the last private method with the comment "myclass.scoreReportHandler is not abstract and does not override abstract method actionPerformed(ActionEvent) in ActionListener. Create sublass, create testclass." I have implemented this method.

If i insert a new method, or even a blank line, the highlight moves to that lines.

This seems to be the source of the problems i am having with dependency, but im not sure. Any thoughts? Thanks in advance
 
Dave Tolls
Ranch Foreman
Posts: 3061
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have your own ActionEvent class somewhere?
Or possibly from another package/jar file?

Use the IDE to ctrl-leftclick on the ActionEvent class in your actionPerformed() and see where it takes you.
Have you marked actionPerformed with @Override?
Does the IDE complain?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!