ClassNotFoundException when two classes are defined in the same java file [message #32564] |
Wed, 15 July 2009 12:20  |
Eclipse User |
|
|
|
Hi,
When I have two classes defined in the same java file and I try to run
the MIDlet in the emulator, I am getting a ClassNotFoundException. The
emulator does not find the second class in the file. I looked at the
generated jar file and the .class is not there. It's like only the .class
files that coincide with the .java files names are added. If I remove the
class definition from the file and create a new .java file containing that
class, it works properly. Does this happened to someone?
I am using Eclipse 3.3 and MTJ 1.0.
Thanks in advance,
Pablo
|
|
|
|
|
|
|
Re: ClassNotFoundException when two classes are defined in the same java file [message #32734 is a reply to message #32702] |
Wed, 15 July 2009 19:11   |
Eclipse User |
|
|
|
Hi David,
Thanks for your answer. Below I pasted the .java file that is giving
me that error. However, I tried also to compile J4ME and since it has some
files in where two classes are defined, I am getting the same error. Let
me know if you need more info.
I looked at the .mtj.tmp folder in the project and this is the
content of that dir:
mtj.tmp
SlideShow.jad
SlideShow.jar
verified
classes
SlideShow.class
SSCanvas.class
libs
The content of the SlideShow.jar file is:
META-INF
MANIFEST.MF
SlideShow.Class
pngtest16rgba.png
pnggrad8rgb.png
and the exact error is:
Running with storage root C:\Documents and
Settings\yo\j2mewtk\2.5.2\appdb\DefaultColorPhone
Running with locale: Spanish_Argentina.1252
Running in the identified_third_party security domain
java.lang.NoClassDefFoundError: SSCanvas
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)
Execution completed.
3405897 bytecodes executed
16 thread switches
1668 classes in the system (including system classes)
17652 dynamic objects allocated (529312 bytes)
2 garbage collections (458848 bytes collected)
------------------------------------------------------------ -----
//file: SlideShow.java
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class SlideShow extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private SSCanvas screen;
public SlideShow() {
// Get the Display object for the MIDlet
display = Display.getDisplay(this);
// Create the Exit command
exitCommand = new Command("Exit", Command.EXIT, 2);
// Create the main screen form
screen = new SSCanvas();
// Set the Exit command
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// Set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class SSCanvas extends Canvas {
private Image[] slides;
private String[] captions = { "Automotive", "Beauty", "Construction",
"Pest Control", "Pet Store", "Restaurant" };
private int curSlide = 0;
public SSCanvas() {
// Load the slide show images
try {
slides = new Image[2];
slides[0] = Image.createImage("/pnggrad8rgb.png");
slides[1] = Image.createImage("/pngtest16rgba.png");
}
catch (IOException e) {
System.err.println("Failed loading images!");
}
}
public void keyPressed(int keyCode) {
// Get the game action from the key code
int action = getGameAction(keyCode);
// Process the left and right buttons
switch (action) {
case LEFT:
if (--curSlide < 0)
curSlide = slides.length - 1;
repaint();
break;
case RIGHT:
if (++curSlide >= slides.length)
curSlide = 0;
repaint();
break;
}
}
public void paint(Graphics g) {
// Clear the display
g.setColor(255, 255, 255); // White
g.fillRect(0, 0, getWidth(), getHeight());
// Draw the current image
g.drawImage(slides[curSlide], getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.VCENTER);
// Set the font for the caption
Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_MEDIUM);
g.setFont(f);
// Draw the current caption
g.setColor(0, 0, 0); // Black
g.drawString(captions[curSlide], getWidth() / 2, 0,
Graphics.HCENTER | Graphics.TOP);
}
}
Regards,
Pablo
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: ClassNotFoundException when two classes are defined in the same java file [message #575023 is a reply to message #32598] |
Wed, 15 July 2009 14:20  |
Eclipse User |
|
|
|
Hi Diego,
Thanks for your answer. I did have the source file included in the
build properties. The problem is that I have only one .java file that
contains two classes defined inside. After compiling this .java file the
compiler generates two .class files. Only the .class file that has the
same name than the .java file is included in the .jar package. The other
class file is not included in the file and that is why I am getting the
ClassNotFound exception.
I don't know why both .class are not included in the .jar, is there a
configuration for this? Maybe somewhere to configure how the .jar file is
generated?
Regards,
Pablo
|
|
|
|
|
Re: ClassNotFoundException when two classes are defined in the same java file [message #575094 is a reply to message #32702] |
Wed, 15 July 2009 19:11  |
Eclipse User |
|
|
|
Hi David,
Thanks for your answer. Below I pasted the .java file that is giving
me that error. However, I tried also to compile J4ME and since it has some
files in where two classes are defined, I am getting the same error. Let
me know if you need more info.
I looked at the .mtj.tmp folder in the project and this is the
content of that dir:
mtj.tmp
SlideShow.jad
SlideShow.jar
verified
classes
SlideShow.class
SSCanvas.class
libs
The content of the SlideShow.jar file is:
META-INF
MANIFEST.MF
SlideShow.Class
pngtest16rgba.png
pnggrad8rgb.png
and the exact error is:
Running with storage root C:\Documents and
Settings\yo\j2mewtk\2.5.2\appdb\DefaultColorPhone
Running with locale: Spanish_Argentina.1252
Running in the identified_third_party security domain
java.lang.NoClassDefFoundError: SSCanvas
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)
Execution completed.
3405897 bytecodes executed
16 thread switches
1668 classes in the system (including system classes)
17652 dynamic objects allocated (529312 bytes)
2 garbage collections (458848 bytes collected)
------------------------------------------------------------ -----
//file: SlideShow.java
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class SlideShow extends MIDlet implements CommandListener {
private Command exitCommand;
private Display display;
private SSCanvas screen;
public SlideShow() {
// Get the Display object for the MIDlet
display = Display.getDisplay(this);
// Create the Exit command
exitCommand = new Command("Exit", Command.EXIT, 2);
// Create the main screen form
screen = new SSCanvas();
// Set the Exit command
screen.addCommand(exitCommand);
screen.setCommandListener(this);
}
public void startApp() throws MIDletStateChangeException {
// Set the current display to the screen
display.setCurrent(screen);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
class SSCanvas extends Canvas {
private Image[] slides;
private String[] captions = { "Automotive", "Beauty", "Construction",
"Pest Control", "Pet Store", "Restaurant" };
private int curSlide = 0;
public SSCanvas() {
// Load the slide show images
try {
slides = new Image[2];
slides[0] = Image.createImage("/pnggrad8rgb.png");
slides[1] = Image.createImage("/pngtest16rgba.png");
}
catch (IOException e) {
System.err.println("Failed loading images!");
}
}
public void keyPressed(int keyCode) {
// Get the game action from the key code
int action = getGameAction(keyCode);
// Process the left and right buttons
switch (action) {
case LEFT:
if (--curSlide < 0)
curSlide = slides.length - 1;
repaint();
break;
case RIGHT:
if (++curSlide >= slides.length)
curSlide = 0;
repaint();
break;
}
}
public void paint(Graphics g) {
// Clear the display
g.setColor(255, 255, 255); // White
g.fillRect(0, 0, getWidth(), getHeight());
// Draw the current image
g.drawImage(slides[curSlide], getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.VCENTER);
// Set the font for the caption
Font f = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_MEDIUM);
g.setFont(f);
// Draw the current caption
g.setColor(0, 0, 0); // Black
g.drawString(captions[curSlide], getWidth() / 2, 0,
Graphics.HCENTER | Graphics.TOP);
}
}
Regards,
Pablo
|
|
|
Re: ClassNotFoundException when two classes are defined in the same java file [message #575120 is a reply to message #32734] |
Wed, 15 July 2009 20:47  |
Eclipse User |
|
|
|
This is also the output from the MTJ Build console running eclipse with
the following options:
eclipse -vmargs -Dmtj.build.logging=all
> PreverificationBuilder.clean project = P/SlideShow
> PreverificationBuilder.cleanProject project = P/SlideShow
< PreverificationBuilder.cleanProject project = P/SlideShow
< PreverificationBuilder.clean project = P/SlideShow
> PreverificationBuilder.clean project = P/SlideShow
> PreverificationBuilder.cleanProject project = P/SlideShow
< PreverificationBuilder.cleanProject project = P/SlideShow
< PreverificationBuilder.clean project = P/SlideShow
> PreverificationBuilder.build project = P/SlideShow
> PreverificationBuilder.preverifyProject project = P/SlideShow
> ResourceDeltaBuilder.build
> ResourceDeltaBuilder.handleClassAddsAndChanges; classFiles count = 2
======================== Launching Preverification
=========================
======================== Preverification exited with code: 0
< ResourceDeltaBuilder.handleClassAddsAndChanges
< ResourceDeltaBuilder.build
< PreverificationBuilder.preverifyProject project = P/SlideShow
> PreverificationBuilder.preverifyLibraries project = P/SlideShow
< PreverificationBuilder.preverifyLibraries project = P/SlideShow
< PreverificationBuilder.build project = P/SlideShow
> PreverificationBuilder.build project = P/SlideShow
> PreverificationBuilder.preverifyProject project = P/SlideShow
> ResourceDeltaBuilder.build
> ResourceDeltaBuilder.handleClassAddsAndChanges; classFiles count = 0
< ResourceDeltaBuilder.handleClassAddsAndChanges
< ResourceDeltaBuilder.build
< PreverificationBuilder.preverifyProject project = P/SlideShow
> PreverificationBuilder.preverifyLibraries project = P/SlideShow
< PreverificationBuilder.preverifyLibraries project = P/SlideShow
< PreverificationBuilder.build project = P/SlideShow
Thanks,
Pablo
|
|
|
Re: ClassNotFoundException when two classes are defined in the same java file [message #575132 is a reply to message #32734] |
Thu, 16 July 2009 09:31  |
Eclipse User |
|
|
|
Hello again Pablo,
It seems that you found a bug on our implementation. The class file is not
being included on the application package because the package builder is
not including it since it is not handling top level classes other than the
main public class within a java file. In order to solve your problem for
now consider moving the SSCanvas class into the SlideShow class (make the
SSCanvas an inner class of the SlideShow class). I will open a bug for
this issue and will make sure it gets solved as soon as possible.
Regards,
David Marques
|
|
|
|
|
|
|
|
|
|