java.lang.NullPointerException

Appcelerator JIRA | Paul Mietz Egli | 3 years ago
  1. 0

    My app reuses an AlertDialog object with a custom view. The first time I call show() on the dialog, it successfully displays. When I hide it using either a cancel button or the back button, then redisplay the same dialog object, I get the following NullPointerException: {code} E/TiApplication( 2042): java.lang.NullPointerException E/TiApplication( 2042): at org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256) E/TiApplication( 2042): at ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73) E/TiApplication( 2042): at android.os.Handler.handleCallback(Handler.java:615) E/TiApplication( 2042): at android.os.Handler.dispatchMessage(Handler.java:92) E/TiApplication( 2042): at android.os.Looper.loop(Looper.java:137) E/TiApplication( 2042): at android.app.ActivityThread.main(ActivityThread.java:4745) E/TiApplication( 2042): at java.lang.reflect.Method.invokeNative(Native Method) E/TiApplication( 2042): at java.lang.reflect.Method.invoke(Method.java:511) E/TiApplication( 2042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) E/TiApplication( 2042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) E/TiApplication( 2042): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 2042): FATAL EXCEPTION: main E/AndroidRuntime( 2042): java.lang.NullPointerException E/AndroidRuntime( 2042): at org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73) E/AndroidRuntime( 2042): at android.os.Handler.handleCallback(Handler.java:615) E/AndroidRuntime( 2042): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 2042): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 2042): at android.app.ActivityThread.main(ActivityThread.java:4745) E/AndroidRuntime( 2042): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 2042): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 2042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) E/AndroidRuntime( 2042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) E/AndroidRuntime( 2042): at dalvik.system.NativeStart.main(Native Method) {code} This appears to be happening because the TiUIDialogProxy.hide() method sets the custom view to null. The workaround is to set the androidView property on the dialog immediately before calling show() instead of setting it in the creation dict as illustrated below: {code:javascript} var win = Ti.UI.createWindow({ backgroundColor: 'white' }); var view = Ti.UI.createView({ }); var alertDialog = Ti.UI.createAlertDialog({ androidView: view, // for workaround, remove this line buttonNames: ["Ok", "Close"], cancel: 1 }); var button = Ti.UI.createButton({ title: 'Show Dialog' }); button.addEventListener('click', function(e) { // alertDialog.androidView = view; // for workaround, uncomment this line alertDialog.show(); }); win.add(button); win.open(); {code}

    Appcelerator JIRA | 3 years ago | Paul Mietz Egli
    java.lang.NullPointerException
  2. 0

    My app reuses an AlertDialog object with a custom view. The first time I call show() on the dialog, it successfully displays. When I hide it using either a cancel button or the back button, then redisplay the same dialog object, I get the following NullPointerException: {code} E/TiApplication( 2042): java.lang.NullPointerException E/TiApplication( 2042): at org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92) E/TiApplication( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256) E/TiApplication( 2042): at ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73) E/TiApplication( 2042): at android.os.Handler.handleCallback(Handler.java:615) E/TiApplication( 2042): at android.os.Handler.dispatchMessage(Handler.java:92) E/TiApplication( 2042): at android.os.Looper.loop(Looper.java:137) E/TiApplication( 2042): at android.app.ActivityThread.main(ActivityThread.java:4745) E/TiApplication( 2042): at java.lang.reflect.Method.invokeNative(Native Method) E/TiApplication( 2042): at java.lang.reflect.Method.invoke(Method.java:511) E/TiApplication( 2042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) E/TiApplication( 2042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) E/TiApplication( 2042): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime( 2042): FATAL EXCEPTION: main E/AndroidRuntime( 2042): java.lang.NullPointerException E/AndroidRuntime( 2042): at org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256) E/AndroidRuntime( 2042): at ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73) E/AndroidRuntime( 2042): at android.os.Handler.handleCallback(Handler.java:615) E/AndroidRuntime( 2042): at android.os.Handler.dispatchMessage(Handler.java:92) E/AndroidRuntime( 2042): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime( 2042): at android.app.ActivityThread.main(ActivityThread.java:4745) E/AndroidRuntime( 2042): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime( 2042): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime( 2042): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) E/AndroidRuntime( 2042): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) E/AndroidRuntime( 2042): at dalvik.system.NativeStart.main(Native Method) {code} This appears to be happening because the TiUIDialogProxy.hide() method sets the custom view to null. The workaround is to set the androidView property on the dialog immediately before calling show() instead of setting it in the creation dict as illustrated below: {code:javascript} var win = Ti.UI.createWindow({ backgroundColor: 'white' }); var view = Ti.UI.createView({ }); var alertDialog = Ti.UI.createAlertDialog({ androidView: view, // for workaround, remove this line buttonNames: ["Ok", "Close"], cancel: 1 }); var button = Ti.UI.createButton({ title: 'Show Dialog' }); button.addEventListener('click', function(e) { // alertDialog.androidView = view; // for workaround, uncomment this line alertDialog.show(); }); win.add(button); win.open(); {code}

    Appcelerator JIRA | 3 years ago | Paul Mietz Egli
    java.lang.NullPointerException
  3. 0

    Android: Saving Map State in Google map

    Stack Overflow | 11 months ago | Junie Negentien
    java.lang.RuntimeException: Unable to resume activity {com.ourThesis.junieNegentien2015/com.ourThesis.junieNegentien2015.MainActivity}: java.lang.NullPointerException
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.NullPointerException

      No message provided

      at org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity()
    2. org.appcelerator.titanium
      TiBaseActivity$DialogWrapper.getActivity
      1. org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103)
      1 frame
    3. ti.modules.titanium
      AlertDialogProxy$1.run
      1. ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165)
      2. ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92)
      3. ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256)
      4. ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73)
      4 frames
    4. Android Platform
      ActivityThread.main
      1. android.os.Handler.handleCallback(Handler.java:615)
      2. android.os.Handler.dispatchMessage(Handler.java:92)
      3. android.os.Looper.loop(Looper.java:137)
      4. android.app.ActivityThread.main(ActivityThread.java:4745)
      4 frames
    5. Java RT
      Method.invoke
      1. java.lang.reflect.Method.invokeNative(Native Method)
      2. java.lang.reflect.Method.invoke(Method.java:511)
      2 frames
    6. Android
      ZygoteInit.main
      1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
      2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
      2 frames
    7. Android Platform
      NativeStart.main
      1. dalvik.system.NativeStart.main(Native Method)
      1 frame