views:

1451

answers:

6

I'm trying to write an application for Android and when I launch my new activity, I've set break points and found that it runs through my onCreate without any errors, but after that function returns, the debugger says there is a NullPointer Exception. The problem is, its not in my code, it says its in ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2268 and where the source normally would be (if it were my code) I just get "Source not found." and a button that says "Edit Source Lookup Path"

How can I setup eclipse so I can debug this problem? I'm sure I'm doing something wrong in my code, but because the exception originates in code I can't see, I have no idea how to figure out where the problem is.

I'm using android-sdk-linux_x86-1.5_r3 and my G1 for this project.

UPDATE: I think my question really has more to do with android development than using eclipse. I'm not sure where to find the source for the the code that is throwing the exception. Maybe there is a way I can debug it without having that file, but I'm not sure what it would be.

+2  A: 

a button that says "Edit Source Lookup Path"

Hit that button and tell Eclipse where to find the source code for that method. That should help. At least you'll be able to step into it in the debugger and read something more sensible.

duffymo
+1  A: 

I haven't worked with Andriod, but Eclipse should be able to show you the call stack. Look at the point where the program exits your code and enters someone else's, and make sure all your variables correct (non-null, contain the "right" data, etc).

atk
None of my code is in the call stack. My code runs within android, so it seems like android is expecting me to set something up, but I'm not sure how to find what that something is.
Asa Ayers
atk
+2  A: 

Could you show the full call stack?

Usually, at least with Android, an exception triggers two separate traces. The first one is useless. The second one, noted by "Caused by exception", is the one you want.

And, even if neither stack trace has your code, we might recognize something by seeing the whole thing.

CommonsWare
A: 

Even if it's happening within the Android code, you should still be able to narrow down at what point it's happening and which of your variables it doesn't like. Yeah, vague answer, not much else to say. Or download the source and tell Eclipse where it is.

Rob Lourens
+1  A: 

Your going in assumption should be the NPE is caused by you, not Android. The NPE may pop at ActivityThread.performLaunchActivity(ActivityThread$ActivityRecord) line: 2268 but that means you passed a null pointer to something and it kept on getting passed around until performLaunchActivity actually tried using it and crashed when it found a null pointer.

If we can see the full LogCat, particularly everything in red in the Eclipse LogCat it would help for debugging. I've turned myself inside out looking for an NPE only for someone else to find a very subtle resource initializing line out of place.

Will
Thank you. The stacks didn't seem to help me, but if I look at the LogCat, it said where my code was interacting and was able to show me exactly where my problem was.
Asa Ayers
+2  A: 

Was wondering this myself, and even though it showed the "caused by" in the logcat, I wanted the debugger to actually break where the NullPointer was thrown (even though it was being caught)

Here's how:

  1. Run -> Add Java Exception Breakpoint
  2. Find NullPointerException (or whatever else you might be debugging (the "Caused by" exception)
  3. Make sure Suspend On Caught Exceptions is checked. Click OK.
  4. You should see a new breakpoint in your view

Try running it now, and the debugger should break where it actually occurs.

mikelikespie