You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "mike billau (JIRA)" <ji...@apache.org> on 2013/02/18 20:27:13 UTC

[jira] [Commented] (CB-2458) Clicking back button while app is loading causes a NPE

    [ https://issues.apache.org/jira/browse/CB-2458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13580791#comment-13580791 ] 

mike billau commented on CB-2458:
---------------------------------

Hello. This bug can be caused in two ways.
1. in config.xml, set UseBrowserHistory=true. Then when the app is loading and they hit the Back button before loadURL() is called, they get the above NPE. I "fixed" this by null fencing the code in startOfHistory(). This works alright - when the user hits the Back button, it is ignored and nothing happens. However, I think that the expected behavior would be to exit the app. I tried doing this by adding this.cordova.getActivity().finish() inside of the onKeyUp() but was getting a new NPE and I'm not sure why. What is weird is that this new NPE is the same one that the user will see in scenario 2 below.
2. in config.xml, set UseBrowserHisotry=false. Now when the app is loading up, if they hit the Back button, the app exits and gives us a new NPE (different from above):
02-18 13:03:17.701: E/AndroidRuntime(25565): FATAL EXCEPTION: main
02-18 13:03:17.701: E/AndroidRuntime(25565): java.lang.RuntimeException: Unable to destroy activity {com.b/com.b.b}: java.lang.NullPointerException
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3451)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3469)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.app.ActivityThread.access$1200(ActivityThread.java:141)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.os.Handler.dispatchMessage(Handler.java:99)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.os.Looper.loop(Looper.java:137)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at android.app.ActivityThread.main(ActivityThread.java:5039)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at java.lang.reflect.Method.invokeNative(Native Method)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at java.lang.reflect.Method.invoke(Method.java:511)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at dalvik.system.NativeStart.main(Native Method)
02-18 13:03:17.701: E/AndroidRuntime(25565): Caused by: java.lang.NullPointerException
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at java.lang.String.indexOf(String.java:984)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at org.apache.cordova.CordovaWebView.loadUrlNow(CordovaWebView.java:465)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at org.apache.cordova.CordovaWebView.loadUrl(CordovaWebView.java:350)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at org.apache.cordova.CordovaWebView.handleDestroy(CordovaWebView.java:868)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	at org.apache.cordova.DroidGap.onDestroy(DroidGap.java:710)
02-18 13:03:17.701: E/AndroidRuntime(25565): 	... 11 more

Does anybody have any advice? Why does calling handleDestory() before loadURL() result in an NPE?
                
> Clicking back button while app is loading causes a NPE
> ------------------------------------------------------
>
>                 Key: CB-2458
>                 URL: https://issues.apache.org/jira/browse/CB-2458
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Android
>    Affects Versions: 2.3.0, 2.4.0
>            Reporter: Simon MacDonald
>            Assignee: Simon MacDonald
>             Fix For: 2.5.0
>
>
> Basically the problem is that they have a situation where the user will hit the "back" button before loadURL() has been called, causing an NPE and a bad exit.
> 02-18 09:49:35.681: E/AndroidRuntime(18993): FATAL EXCEPTION: main
> 02-18 09:49:35.681: E/AndroidRuntime(18993): java.lang.NullPointerException
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at org.apache.cordova.CordovaWebView.startOfHistory(CordovaWebView.java:912)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at org.apache.cordova.CordovaWebView.onKeyDown(CordovaWebView.java:719)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.KeyEvent.dispatch(KeyEvent.java:2609)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.View.dispatchKeyEvent(View.java:7198)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1354)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.webkit.WebView.access$701(WebView.java:262)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.webkit.WebView$PrivateAccess.super_dispatchKeyEvent(WebView.java:1786)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.webkit.WebViewClassic.dispatchKeyEvent(WebViewClassic.java:5716)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.webkit.WebView.dispatchKeyEvent(WebView.java:2110)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1359)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1920)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1395)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.app.Activity.dispatchKeyEvent(Activity.java:2370)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1847)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3701)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewRootImpl.handleImeFinishedEvent(ViewRootImpl.java:3651)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:2818)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.os.Handler.dispatchMessage(Handler.java:99)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.os.Looper.loop(Looper.java:137)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at android.app.ActivityThread.main(ActivityThread.java:5039)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at java.lang.reflect.Method.invokeNative(Native Method)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at java.lang.reflect.Method.invoke(Method.java:511)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
> 02-18 09:49:35.681: E/AndroidRuntime(18993): 	at dalvik.system.NativeStart.main(Native Method) 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira