Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException - Can't figure this out

 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hemant Sareen
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "res/" directory needs to be just under the top level directory of your JAR package.
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank:
You don't have to specify 'res' in the path just use "/image_name"..
Hope it works..
 
Greg Schwartz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic