Skip to main content

Testing MIDlet java\lang\ClassNotFoundException

10 replies [Last post]
Joined: 2008-01-02

I am trying to test a MIDlet on Sun's wireless toolkit for CLDC's. I have so far been able to compile, preverify and package a MIDlet. Now trying to test the MIDlet as per the tutorial
The MIDlet appears on the emulator, but when I tried to run the MIDlet I got this
Running with locale: English_United Kingdom.1252
Running in the identified_third_party security domain
Unable to create MIDlet com.j2me.part1.DateTimeApp
java.lang.ClassNotFoundException: com/j2me/part1/DateTimeApp
at com.sun.midp.midlet.MIDletState.createMIDlet(+29)
Execution completed.
5274009 bytecodes executed
119142 thread switches
1668 classes in the system (including system classes)
18354 dynamic objects allocated (576608 bytes)
2 garbage collections (461336 bytes collected)
Has anyone come across this before?
I have queried "com.sun.midp.midlet.MIDletState.createMIDlet(+29)", but haven't seen anything that will resolve the issue.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-15


Please post a listing of the jar file. This can be done with the "jar -tvf DateTimeApp.jar" command. That will me see if the jar is setup right. If you could also post the directory listing of the jar, and the contents of the Jad file.

I have this project setup at home, so I'll check the info this evening, and see where the issues are.

Keep up your exploration.

Joined: 2008-01-02

Ok my jad file is as per tutorial (copy & paste job)
MIDlet-1: DateTimeApp, , com.j2me.part1.DateTimeApp
MIDlet-Name: DateTimeApp
MIDlet-Version: 1.0.0
MIDlet-Vendor: Vikram Goyal
MIDlet-Jar-URL: DateTimeApp.jar
MIDlet-Jar-Size: 391
MicroEdition-Profile: MIDP-2.0
MicroEdition-Configuration: CLDC-1.0

c:\WTK2.5.2\com\output>jar -tvf DateTimeApp.jar
0 Mon Jan 07 07:11:06 GMT 2008 META-INF/
146 Mon Jan 07 07:11:08 GMT 2008 META-INF/MANIFEST.MF

Dir listing is

under com\

under output\


Joined: 2003-06-15

Well looking at the output from jar -tvf you are missing the class file for DateTimeApp
you should have a com/j2me/part1 directory in the jar file.
Also your MIDlet-Jar-Size may be incorrect as well, it will need to be the size of the DateTimeApp.jar file, and in your case it only has a 146byte manifest file. I would imagine that the jar file would be smaller than 146bytes since it should be compress somewhat.
(but maybe not since there are not more files to compress against).

Also I was looking for a directory listing that had the sizes of the files. (not sure what the option is in windows, I use linux, and for me it's "ls -l").

In the bin directory you should have the preverified classes and should be able to do
jar -cvfm ../DateTimeApp.jar ../output/ *
from within the bin directory to get a correct Jarfile.


Joined: 2008-01-02

What I know now is that the compiling worked as far as DataTimeApp.class was created in c:\WTK2.5.2\com\src, and not in com\j2me\part1 as expected.
c:\WTK2.5.2\bin>javac -bootclasspath .;..\lib\midpapi20.jar;..\lib\cldcapi11.jar c:\WTK2.5.2\com\src\

After running preverify.exe, although no errors were stated, No others files were created/added.
c:\WTK2.5.2\com>c:\WTK2.5.2\bin\preverify.exe -classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:\WTK\lib\cldcapi11.jar -d bin classes

I ran jar -cvfm ..\com\output\DateTimeApp.jar ..\com\output\* from the bin dir and the result was "added manifest".

The 3 files in the output dir are each 1 KB in size. As far as I can tell, the size attribute in the jad file is not an issue, as I tried the running the emulator with the same size file (4096) as in the actual tutorial and the emulator would not open, stating the size of the jad file was incorrect. Now, the Q is why the preverification didn't do anything seemingly?

Joined: 2003-06-15

Please look back at the post where I state the 4 steps to do for compiling and preverifying.

In step 3 you execute the javac command from the directory that contains the src bin and classes subdirectories. You executed preverify.exe in the correct directory, but because there were no files in the classes directory nothing was preverified, and there were no errors.

You also are not setting the -d classes option on the compile statement as was stated in step 3 of the previous thread.

That should fix it to the point you have a valid jar file. I know command-line is confusing, but you just about have it. :)


Joined: 2008-01-02

As per step 3 in previous thread
c:\WTK2.5.2\com>javac -bootclasspath c:\WTK2.5.\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar -d classes src\*.java
this gave me
src\ class : com.j2me.part1.DateTimeApp
public class DateTimeApp extends MIDlet {
1 error

Joined: 2003-06-15

I tried some stuff to reproduce this error and can't but I think you have something out of sync, and the classpath maybe causing an issue.

I would suggest starting over again, by removing the c:\wtk2.5.2\com\bin and c:\wtk2.5.2\com\classes directories.
Then you should check C:\WTK2.5.2\bin for com/j2me/part1 directories and I would remove them and the DateTimeApp.class file that is in it.

Also check that you only have 1 java file in the src directory. Windows is notorious for messing up the case on the files. So a file that is and to Windows appear to be the same when a program tries to access it.

Make sure you don't have a CLASSPATH environment variable set that might point somewhere else.

Personally, I would not put source in the WTK2.5.2 directory. That way if you upgrade later to a newer version you don't accidentally uninstall it and thus delete all of your files.

I usually have a proj directory (eg. C:\projs) and then have a directory for each project.

Hope that helps.

Joined: 2008-01-02

If in doubt start over, exactly. Refreshed the directories. I compiled
and this created
I then preverified using
c:\WTK2.5.2\bin\preverify.exe -classpath
.;c:WTK2.5.\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar com.j2me.part1.DateTimeApp
which created
Added to output folder
created jar file
c:\WTK2.5.2\classes\output>jar cvfm DateTimeApp.jar .\com
which created
added manifest
adding com/(in = 0) (out = 0)(stored 0%)
adding com/j2me/(in = 0) (out = 0)(stored 0%)
adding com/j2me/part1/(in = 0) (out = 0)(stored 0%)
adding com/j2me/part1/DateTimeApp.class(in = 882) (out = 489)(deflated 44%)
To test this
from the output dir:
c:\WTK2.5.2\bin\emulator.exe -Xdescriptor DateTimeApp.jad
Emulaor opened with DateTimeApp MIDlet listed
attempted to load MIDlet :

Method .......: 10233084 'com/sun/midlet/MIDletState.createMIDlet (static)
Alert : java/lang/ClassFormatError: Bad version information
On checking this out, the version info seems to relate to the jdk compiler version
I tried recompiling using javac -target 1.4 -source 1.4 .....
but this had no affect. Still looking into it! Almost there.

Joined: 2003-06-15

Well you were on the right path with the -target/source options, however JavaME needs to have a target of 1.1, and I found using JDK6 that the 1.2 was the lowest I could go on source.

So try using javac -target 1.1 - source 1.2 ..... and see if that does it for you.

FYI.. Here is a link to various mobile&embedded java info.

Joined: 2008-01-02

Shawn - good call!
recompiled with javac -target 1.1 -source 1.2
it worked!
Thanks again.