Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-14505

Android: NullPointerException when reusing an AlertDialog that contains an androidView

    Details

      Description

      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:

       
      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)
      

      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:

      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();
      

        Attachments

          Activity

            People

            • Assignee:
              bijuexalture Biju pm
              Reporter:
              pegli Paul Mietz Egli
              Reviewer:
              Vishal Duggal (Inactive)
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-16949
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code