Skip to main content

Error loading class

13 replies [Last post]
rpjd
Offline
Joined: 2008-01-02
Points: 0

I am doing the J2ME tutorial here:
http://today.java.net/pub/a/today/2005/02/09/j2me1.html?page=2
I have successfully compiled DateTimeApp .java as DateTimeApp.class was created
In the next step I am trying to preverify using:
c:\WTK2.5.2\bin>preverify1.0.exe -classpath ..\lib\cldcapi11.jar;..\lib\midpapi20.jar com.j2me.part1.DateTimeApp
as in the tutorial but it failed due to
Error loading class com.j2me.part1.DateTimeApp
I also tried this using the full class path, but with no luck.
Can anyone tell me what might have caused this error? Any tips or pointers appreciated.

Reply viewing options

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

you need semicolons between the jars, as in:
javac -bootclasspath c:\WTK2.5.2\lib\cldcapi11.jar;c:\WTK2.5.2\lib\madpapi20.jar c:\WTK2.5.2\com\j2me\part1\DateTimeApp.java

See if that works for you.

-Shawn

rpjd
Offline
Joined: 2008-01-02
Points: 0

Suggestion appreciated Shawn.
I tried this:
c:\WTK2.5.2\bin>preverify1.0.exe -classpath c:\WTK2.5.2\lib\cldcapi11.jar;c:\WTK2.5.2\lib\midpapi20.jar c:\WTK2.5.2\com\j2me\part1\DateTimeApp
instead, but it gave me:
Unable to load class c:\WTK2.5.2\com\j2me\part1\DateTimeApp

Can you think of anything else I could try? Thanks again.

rpjd
Offline
Joined: 2008-01-02
Points: 0

I tried this also:
c:\WTK2.5.2\com\j2me\part1>c:\WTK2.5.2\bin\preverify1.0.exe -classpath c:\WTK2.5.2\lib\cldcapi11.jar;c:\WTK2.5.2\lib\midpapi20.jar -d . DateTimeApp
However this gave me
Error preverifying class DateTimeApp
Class loading error: Wrong Name

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Opps sorry on that last one, it looked like your other post.

However here you need to add to -classpath the current path. That is to say, when you specify a classpath on the command line it only uses that path and does not include the current directory. So try this:
preverify1.0.exe -d . -classpath .\;c:\WTK2.5.2\lib\cldcapi11.jar;c:\WTK2.5.2\lib\midpapi20.jar DateTimeApp

Which I'm assuming that DateTimeApp.class is in the current directory.
Also your class name must include the package if there is one. Meaning if your DateTimeApp.java has at the top a line of "package com.j2me;" then you need to have com.j2me.DateTimeApp not just DateTimeApp

Also Kudos for going to the command-line, and not just using the WTK GUI tools. You will understand more of what J2me is about this way, than if you just clicked and pointed at ktoolbar to build your app.

-Shawn

rpjd
Offline
Joined: 2008-01-02
Points: 0

Thanks again for the suggestion. My latest effort:
c:WTK2.5.2\com\j2me\part1>c:\WTK2.5.2\bin\preverify1.0.exe
-classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar com.j2me.part1.DateTimeApp
where com.j2me.part1 is the package at the top of DateTimeApp.java
This gave me:
Error loading class com.j2me.part1.DateTimeApp

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Arrgghh... I hate this error. It's one of those magic directory things. But it good in that forces you to keep your source code and compiled code separate.
Ok buckle up... here we go.

1) create 3 directories. src classes bin
2) put your DateTimeApp.java in the src directory
3) from the directory where you created these 3 directories issue this compile command
javac -bootclasspath c:\WTK2.5.2\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar -d classes src/*.java

4) then issue this preverify command
c:\WTK2.5.2\bin\preverify.exe classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar -d bin classes

That should work for you. Note: you have been selecting the preverify1.0.exe and I'm using the preverify.exe which appears to call the more current preverify1.1.exe. With the simple DateTimeApp code any of the 3 should work, but I would stick with the preverify.exe as that is what most often is maintained.

Let's know if that works for ya.
-Shawn

rpjd
Offline
Joined: 2008-01-02
Points: 0

Just as you suggested Shawn:
C:\WTK2.5.2\com>c:\WTK2.5.2\bin\preverify.exe classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:WTK2.5.2\lib\cldcapi11.jar -d bin classes
Error loading class classpath
Error loading class .;c:\WTK2.5.2\lib\midpapi20.jar;c:WTK2.5.2\lib\cldcapi11.jar

Error preverifying class com.j2me.part1.DateTimeApp
java/lang/NoClassDefFoundError: javax/microedition/midlet/MIDlet

This seems odd since DateTimeApp.java imports this!
import javax.microedition.midlet.MIDlet;
Any ideas?

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Oh very sorry. Had a cut-n-paste error.

I left off the '-' before classpath in the command line. It should have been:
c:\WTK2.5.2\bin\preverify.exe -classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:WTK2.5.2\lib\cldcapi11.jar -d bin classes

See if that doesn't do the trick for you.

Again very sorry about that type-o.

-Shawn

PS.. I'm assuming the compile went okay?

rpjd
Offline
Joined: 2008-01-02
Points: 0

As per your suggestion I have C:\WTK2.5.2\com under which I have bin,classes and src folrers. DateTimeApp.java is located in com\src which compiled fine as it created DateTimeApp.class at com\classes\com\j2me\part1
I tried this:

C:\WTK2.5.2\com>c:\WTK2.5.2\bin\preverify.exe -classpath .;..\lib\midpap120.jar;
..\lib\cldcapi11.jar com.j2me.part1.DateTimeApp -d bin classes
but
Error loading class com.j2me.part1.DateTimeApp

I tried using the full path for DateTimeApp as in classes\com\j2me\part1, but that proved ill-fated.

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

Here is the problem, you need to have the fully qualified path. You can not use the ..\ relative path in the -classpath options of the preverify applications.

almost there. :)

rpjd
Offline
Joined: 2008-01-02
Points: 0

I tried that:

C:\WTK2.5.2\com>c:\WTK2.5.2\bin\preverify.exe -classpath .;c:WTK2.5.2\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar com.j2me.part1.DateTimeApp -d bin classes
Error preverifying class java.lang.Class
VERIFIER ERROR java/lang/Class.getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;:
Cannot find class com/sun/midp/io/ResourceInputStream

Have no idea what this means? Any clue?

sfitzjava
Offline
Joined: 2003-06-15
Points: 0

If you look back a couple postings and compare you will see I do not include com.j2me.part1.DateTimeApp in the command-line.
Here is what you need to execute.
c:\WTK2.5.2\bin\preverify.exe -classpath .;c:\WTK2.5.2\lib\midpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar -d bin classes

And you must be in the directory where if you list the directory "dir" you should see
the 3 directories.

rpjd
Offline
Joined: 2008-01-02
Points: 0

Finally, it worked!
C:\WTK2.5.2\bin>javac -bootclasspath ..\lib\midpapi20.jar;..\lib\cldcapi11.jar
c:\WTK2.5.2\com\src\DateTimeApp.java

C:\WTK2.5.2\com>c:\WTK2.5.2\bin\preverify.exe -classpath .;c:WTK2.5.2\lib\moidpapi20.jar;c:\WTK2.5.2\lib\cldcapi11.jar -d com classes

My thanks.