Hi All, I'm learning J2ME, and am absolutely loving it!! I ran into a problem with a sample application I'm working on... I cannot seem to get the MIDlet to run. I keep receiving a NullPointerException. This is the code I'm using:
And the error I receive is this: startApp threw an Exception java.lang.NullPointerException java.lang.NullPointerException at InteractiveGauge.NonInteractiveGauge.startApp(+8) at javax.microedition.midlet.MIDletProxy.startApp(+7) at com.sun.midp.midlet.Scheduler.schedule(+225) at com.sun.midp.dev.DevMIDletSuiteImpl.schedule(+7) at com.sun.midp.Main.runLocalClass(+20) at com.sun.midp.Main.main(+68)
Any help would be greatly appreciated... The book's code is IDENTICAL, so I can't figure out what it is that I'm missing... I'm running it using WTK2.0...
Hi Frank: Please remoive "void" from the statement public void NonInteractiveGauge() so that it becomes the constructor for this Midlet class...it is taking it as a method now...
Joined: Apr 06, 2003
Hemant, Thank you very much... I knew it had to have been something I overlooked... I can't believe I hadn't noticed that one! Thanks again!
Joined: Apr 06, 2003
Alright, I'm having another problem now... I figured that I'd just continue this thread, rather than starting a new one... My problem is now related to reading image files located on my drive. This is the code I'm running:
The problem is that the IOException is ALWAYS being thrown... And it seems as though it's being thrown here:
the images I have area located in the res/ directory located in the same directory as my MIDlet. I've also tried taking out the first slash so that the path is: "res/ff.png", etc., and it doesn't seem to matter. Any ideas on this one would be appreciated! Thanks!
Originally posted by Michael Yuan: The "res/" directory needs to be just under the top level directory of your JAR package.
Hi Michael, So the resource directory is actually two levels below where the MIDlet is located? Does this also apply when the MIDlet is NOT packaged in a JAR file? I get this error when trying to run it from the SunOne Studio...
Joined: Jun 10, 2003
Hi Frank: You don't have to specify 'res' in the path just use "/image_name".. Hope it works..
I had the same problem with images when I had a path such as /res/image.png Your SDK should default to the /res directory when looking for image files so you only need to put /image.png as the path, as Hermant stated.
Thanks for the tip... I'll keep that in mind! Can the "res" directory not be in the same folder as the MIDlet, or is it just better practice to keep them seperated in their own folders? Thanks!
Joined: May 11, 2003
The sdk's that I've been using have a directory for each J2ME application. The jar/jad files reside in this main directory. Also in this directory are "class", "rsc" (the equivalent of your "res") and "src" folders. All of my image files are in the "rsc" folder that is within the MIDlets main folder. Hope this helps.
subject: NullPointerException - Can't figure this out