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

Hunting down an exception

 
Andy Robinson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
The lastest program I've been working on builds just fine, but outputs a nullpointer exception when run.
I've been having some difficulty tracking this null pointer down. What I'd like to konw if theres a way to run your program step by step, which would be a big help in finding it.
I'm just using the KToolbar at the moment. Would it help for me to download another development enviroment like JBuilder or something ?
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with KToolbar. Does it give you a stack trace when the exception is thrown? It will give you a good place to start at least.

Unfortunately, I can't offer much more advice than that as I am a relative newbie to J2ME myself.

Good luck,

Layne
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well the stack trace should give you a clue to the exact line of code that is causing the problem.

Yes another IDE would help step through the code.

Good Luck

Mark
 
Andy Robinson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not giving me a stack trace, thats a big part of the problem, the exception could be anywhere
Just out of curiosity what IDE do you guys use ? How helpful are they ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually for J2ME I only use TextPad and compile in the Toolkit. I have used IntelliJ Idea, but I haven't tried remote debugging. Wait I take that back, for some reason I think I might have.

But in almost all cases I just read the stack trace.

Mark
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to catch the exception and use exception.printStackTrace() to print the stack trace to the console. Of course, this only works in the emulator. On the real device, your need a logging tool to log the stack trace to RMS or send it to a network server or display it on top of your app screen.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you run the emulator from the command-line, it should print the stack trace directly to the console, IIRC. If not, Michael's suggestion should do the trick.

Layne
 
Andy Robinson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers everyone, the error has now been hunted down and exterminated
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic