Meaningless Drivel is fun!*
The moose likes Java Micro Edition and the fly likes NullPointerException - Can't figure this out Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "NullPointerException - Can Watch "NullPointerException - Can New topic
Author

NullPointerException - Can't figure this out

Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
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...

Thanks!
Frank


-- Frank
Hemant Sareen
Greenhorn

Joined: Jun 10, 2003
Posts: 14
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...
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
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!
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
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!
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
The "res/" directory needs to be just under the top level directory of your JAR package.


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
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...

Thanks,
Frank
Hemant Sareen
Greenhorn

Joined: Jun 10, 2003
Posts: 14
Hi Frank:
You don't have to specify 'res' in the path just use "/image_name"..
Hope it works..
Greg Schwartz
Ranch Hand

Joined: May 11, 2003
Posts: 132
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.


Greg Schwartz<br />Mobatech, LLC<br />greg@mobatech.com<br /><a href="http://www.mobatech.com" target="_blank" rel="nofollow">www.Mobatech.com</a>
Frank Manno
Ranch Hand

Joined: Apr 06, 2003
Posts: 48
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!
Greg Schwartz
Ranch Hand

Joined: May 11, 2003
Posts: 132
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.

Greg
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException - Can't figure this out
 
Similar Threads
Please check this code !!!!
Progress Bar
command button not able to display need help
Doubt from John W.Muchow -core J2ME Technology &MIDP
exception with ImageItem