views:

279

answers:

1

How can I use the numbers in the stacktrace? What do these mean? In eclipse I get often exceptions, for example a NullPointerException:

java.lang.NullPointerException
  at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
  at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
  at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186) 
+12  A: 

Those are the offsets of the instruction that caused the exception from the beginning of the method.

java.lang.NullPointerException
  at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)

The instruction at offset 68 in the method com.sun.midp.lcdui.DefaultEventHandler.commandEvent is causing the actual exception by accessing a null reference.

  at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)

The instruction at offset 47 in the method com.sun.midp.lcdui.AutomatedEventHandler.commandEvent is a call instruction that runs the com.sun.midp.lcdui.DefaultEventHandler.commandEvent method.

  at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)

The instruction at offset 186 in the method com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent is a call instruction that runs the com.sun.midp.lcdui.AutomatedEventHandler.commandEvent method.

Mehrdad Afshari
And in which unit is this offset measured? in line-numbers i guess.. or in instructions? And what does count as a line/instruction? what should be the offset if there is an exception within doSomething2()? if(true){ doSomething1(); doSomething2(); }
hsmit
It's the bytecode offset in the compiled code. Debuggers can use it to map to the line number in the source code. Without the extra debugging information that maps bytecodes to source line numbers, it's not trivial to find the source line just by looking at the number.
Mehrdad Afshari
Ok, thanks! Can you also tell me how to map bytecode offsets to source code line offsets?
hsmit
@hsmit: If you compile the source without debugging information (`javac -g:none source.java`), you can't do that. Otherwise, the JVM should dump the line number for you instead of the offset. Manually reading debugging info from `.class` files requires parsing the binary which is not easy. Why don't you attach a debugger?
Mehrdad Afshari
I'm running my application (midlet) with Eclipse and a wireless toolkit (WTK). I'm not running it in debugging mode.I do not understand what you mean by 'attaching a debugger'.
hsmit
@hsmit: I mean running the program in a debugger (e.g. Eclipse) in your case. If you are building the program without debugging information, you may not be able to find the source line as there's no mapping information generated.
Mehrdad Afshari