Jan 20, 2009

NoClassDefFoundError in Eclipse MTJ

Yesterday I started to implement a new feature in the PatternFormatter for Microlog. A user wanted the ability to print the absolute time. The first implementation was pretty rudimentary, the only available format was the default format used in Log4j's PatternLayout. It worked but today I wanted to improve it. I had planned a snapshot release after that. But I ran into unforeseen troubles. When trying to execute the example MIDlet to try it out, I get the following message in the console window;

java.lang.NoClassDefFoundError: net/sf/microlog/Appender
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
at com.sun.midp.midlet.Scheduler.schedule(+52)
at com.sun.midp.main.Main.runLocalClass(+28)
at com.sun.midp.main.Main.main(+80)

Notice that this is not a classic ClassNotFoundException problem. A ClassNotFoundException is always quite easy to fix. You have to check that you have your classpaths in order. This is something that a every Java developer has to learn to fix, otherwise you do not survive as a Java developer for long. But to fix the NoClassDefFoundError is harder. It basically means that your environment has found the class, but there is something fishy with the bytecode. In this case I have no clue. Is this a compiler problem? Is it a problem with the preverifier? I have done Googling on it, but did not find any relevant answers. Is a problem with Eclipse MTJ? Do you have any clue?

So bear with me, there is a new Microlog snapshot release on its way. I will have to fix the above problem before releasing the code. For the impatient developer, the code is available in the Microlog source repository.

13 comments:

Soulsister said...

I'm not an impatient developer, but I'm a loving wife who still doesn't understand a word you write in your blogposts. Sad but true

Kocham Cie

Kasia

My Open Source Software Development Blog said...

Thank you very much for your interest in my blog. I really appreciate it.

Anonymous said...

Hello, I am getting the same error... did you manage to solve it? ¿How? Thank you soo much!

My Open Source Software Development Blog said...

I created a new workspace and a new project. It seems that the workspace gets corrupted from time to time.

Regards
Johan

Anonymous said...

I had the same problem, but for me it was some libraries that were not checked on the "Order and Export" tab under Java Build Path.

My Open Source Software Development Blog said...

Hi,

the trouble occurred even though I had the correct "Order & export" settings. The setting works for a while, but then it sometimes get corrupted.

Regards
Johan

Anonymous said...

crappy post, didn't give a solution

My Open Source Software Development Blog said...

The objective of the article was not to publish a solution. The blog is intended to give an insight into my thoughts, problems etc I encounter during development. Sometime I publish an article just to start a discussion and maybe to get a solution to a problem.

Thanks for your insightful comment :)

Anonymous said...

I have the same problem all the time, it sucks. It seems that the workspace is corrupt, because if you create a new one it works.

My Open Source Software Development Blog said...

Yes, it is not fun. It would be nice to know what the real problem is and make a better solution than to create a new workspace.

pengantin said...

facing the same error...dunno yet how to fix.

My Open Source Software Development Blog said...

My best bet is you to create a new workspace and start all over again. But that does not always work.

gabriela_st_23 said...

I have the same problem with NoClassDefFound in Android. I created a new workspace,but nothing changed.:( I don't know what to do :((