Friday, November 13, 2009

J2ME: Fixing Cannot find class java/lang/NoClassDefFoundError at preverify

I had a strange error when preverifying a midlet.

     [exec] Error preverifying class temp.TestMidlet
     [exec]     VERIFIER ERROR temp/TestMidlet.()V:
     [exec] Cannot find class java/lang/NoClassDefFoundError

The midlet is ok, Eclipse doesn't display an error. Searching in all the library jars in WTK I found the class NoClassDefFoundError is inside cldcapi11.jar. I modified the cldc jar and nows compiles.

But is not enough for me, I'm not using float or doubles so I want to compile the midlet for CLDC10. So I continued playing and I found the reason: I'm using the field named "class" to obtain the name of a class.


To obtain the Class object of class TestMidlet I'm using the following code:

Class clazz = TestMidlet.class;

this is ok for CLDC11 but for CLDC10 is wrong, I must use this.getClass or something similar.

I hope you can find this useful.



No comments:

Post a Comment