tags:

views:

77

answers:

1

Hello!

Users of my Android app are reporting that they receive a Forced Close message when an incoming call comes in.

I have a Service Receiver and a phone state listener class to determine the status of the phone. When the state is "CALL_STATE_RINGING", I call upon the method stopAllPlayback() in my main Activity. It is at this point that users report "Forced Close" messages.

Can you help me determine where the problem might be? I'm new to Java so I'm not 100% sure how to troubleshoot based on a stack trace.

Here's the stack trace:

java.lang.NullPointerException
at com.tdoo.toodoo.DroidGap.stopAllPlayback(DroidGap.java:190)
at com.tdoo.toodoo.MyPhoneStateListener.onCallStateChanged(MyPhoneStateListener.java:21)
at android.telephony.PhoneStateListener$2.handleMessage(PhoneStateListener.java:319)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

UPDATE: i've just been able to replicate the error myself by putting my phone under a lot of stress (using adb shell monkey), then calling my phone. It seems that this error is occuring on slower phones, but I have the Droid Incredible which is significantly faster.

Does this give anyone any new ideas?

Thanks! Lewis

A: 

com.tdoo.toodoo.DroidGap.stopAllPlayback(DroidGap.java:190)

This line means that the NPE is being thrown from that exact line. I presume DroidGap is your code, what you want to do is look to see what methods are being invoked at the line. If you are lucky, there will be only one.

So if that code looks like:

foo.bar();

Then foo is null.

Armed with this information, it is up to you to determine how foo could be null. Unfortunately the task is much more complicated if you've invoked many methods or performed many member accesses on the same line.

Tim Bender
Thanks, Tim. DroidGap.stopAllPlayback consists only of 1 call to a WebView... For example: appView.loadUrl("javascript:alert('test')"); Is it possible that after some time, the appView becomes null (or the main activity gets unloaded), but yet the PhoneStateListener is still active and making calls to DroidGap.stopAllPlayback() ?
Lewis Sampson
Tim, I just added an update to my OP... Maybe this can help spur an idea.
Lewis Sampson
The gist is, I'm not sure. I can only tell you what typically causes an NPE in Java. Technically, Android isn't even Java (they don't use the JVM, see Oracle sues Google). Based on your feedback, I would say that you have a race condition which allows the `appView` variable to be `null` when the phone rings. Do you construct the WebView within the same callback method? Or do you rely on it existing from previous normal execution?
Tim Bender
I rely on it existing from previous normal execution.
Lewis Sampson