Jump to content
  • Advertisement
Sign in to follow this  

Debugging Android Exceptions

This topic is 2951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, getting started with Android Java Programming coming from C++ and visual studio. I'm writing some code and I keep getting exceptions, but I cannot figure out how to find the source at all through the IDE.

For example, I have a bug in a function filldata() where I am trying to call Float.toString() on a null value. When I hit this point, I get an exception thrown, and if I look in my variables window I see the exception 'e' is of type NullPointerException, which makes sense given that I'm trying to call a function on a null value.

However, I have no idea how I should be tracking these down. The only way I was able to find the line was by stepping through the program line by line until I hit the exception. When I hit the breakpoint, I look at the call stack and there's not a single line in it that references any of my source code.

I feel like I must be missing something, because I've debugged several exceptions so far, but each one takes me 20m to find, because the call stack doesn't give me any information about where I am. Always just a bunch of lines about "ActivityThread".

Where is the actual call stack that says from what function the exception was thrown, etc?

Thread [<1> main] (Suspended (exception RuntimeException))
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1696
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1716
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 124
ActivityThread$H.handleMessage(Message) line: 968
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 130
ActivityThread.main(String[]) line: 3806
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 507
ZygoteInit$MethodAndArgsCaller.run() line: 839
ZygoteInit.main(String[]) line: 597
NativeStart.main(String[]) line: not available [native method]

Share this post

Link to post
Share on other sites
I don't have experience with Android. However, if you allow that suspended thread to continue - this usually results in the full exception stack trace being printed somewhere.

If not, you can catch all exceptions somewhere high enough, call e.printStackTrace() and re-throw the exception (possible wrapped in a RuntimeException). It will include the exact line that created the NullPointerException.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!