{ "id": "116620", "key": "TIMOB-14505", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "15564", "description": "2013 Sprint 15 API", "name": "2013 Sprint 15 API", "archived": true, "released": true, "releaseDate": "2013-07-29" }, { "id": "15567", "description": "2013 Sprint 15", "name": "2013 Sprint 15", "archived": true, "released": true, "releaseDate": "2013-07-29" }, { "id": "14982", "description": "Release 3.2.0", "name": "Release 3.2.0", "archived": false, "released": true, "releaseDate": "2013-12-19" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-07-19T21:24:21.000+0000", "created": "2013-06-28T16:34:34.000+0000", "priority": { "name": "Critical", "id": "1" }, "labels": [ "android", "module_alertdialog", "qe-testadded" ], "versions": [], "issuelinks": [], "assignee": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "updated": "2014-03-14T07:00:06.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "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:\r\n\r\n{code}\r\n\r\nE/TiApplication( 2042): java.lang.NullPointerException\r\nE/TiApplication( 2042): \tat org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103)\r\nE/TiApplication( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165)\r\nE/TiApplication( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92)\r\nE/TiApplication( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256)\r\nE/TiApplication( 2042): \tat ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73)\r\nE/TiApplication( 2042): \tat android.os.Handler.handleCallback(Handler.java:615)\r\nE/TiApplication( 2042): \tat android.os.Handler.dispatchMessage(Handler.java:92)\r\nE/TiApplication( 2042): \tat android.os.Looper.loop(Looper.java:137)\r\nE/TiApplication( 2042): \tat android.app.ActivityThread.main(ActivityThread.java:4745)\r\nE/TiApplication( 2042): \tat java.lang.reflect.Method.invokeNative(Native Method)\r\nE/TiApplication( 2042): \tat java.lang.reflect.Method.invoke(Method.java:511)\r\nE/TiApplication( 2042): \tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)\r\nE/TiApplication( 2042): \tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)\r\nE/TiApplication( 2042): \tat dalvik.system.NativeStart.main(Native Method)\r\nE/AndroidRuntime( 2042): FATAL EXCEPTION: main\r\nE/AndroidRuntime( 2042): java.lang.NullPointerException\r\nE/AndroidRuntime( 2042): \tat org.appcelerator.titanium.TiBaseActivity$DialogWrapper.getActivity(TiBaseActivity.java:103)\r\nE/AndroidRuntime( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.processView(TiUIDialog.java:165)\r\nE/AndroidRuntime( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.processProperties(TiUIDialog.java:92)\r\nE/AndroidRuntime( 2042): \tat ti.modules.titanium.ui.widget.TiUIDialog.show(TiUIDialog.java:256)\r\nE/AndroidRuntime( 2042): \tat ti.modules.titanium.ui.AlertDialogProxy$1.run(AlertDialogProxy.java:73)\r\nE/AndroidRuntime( 2042): \tat android.os.Handler.handleCallback(Handler.java:615)\r\nE/AndroidRuntime( 2042): \tat android.os.Handler.dispatchMessage(Handler.java:92)\r\nE/AndroidRuntime( 2042): \tat android.os.Looper.loop(Looper.java:137)\r\nE/AndroidRuntime( 2042): \tat android.app.ActivityThread.main(ActivityThread.java:4745)\r\nE/AndroidRuntime( 2042): \tat java.lang.reflect.Method.invokeNative(Native Method)\r\nE/AndroidRuntime( 2042): \tat java.lang.reflect.Method.invoke(Method.java:511)\r\nE/AndroidRuntime( 2042): \tat com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)\r\nE/AndroidRuntime( 2042): \tat com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)\r\nE/AndroidRuntime( 2042): \tat dalvik.system.NativeStart.main(Native Method)\r\n{code}\r\n\r\nThis 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:\r\n\r\n{code:javascript}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: 'white'\r\n});\r\nvar view = Ti.UI.createView({\r\n});\r\nvar alertDialog = Ti.UI.createAlertDialog({\r\n androidView: view, // for workaround, remove this line\r\n buttonNames: [\"Ok\", \"Close\"],\r\n cancel: 1\r\n});\r\nvar button = Ti.UI.createButton({\r\n title: 'Show Dialog'\r\n});\r\nbutton.addEventListener('click', function(e) {\r\n // alertDialog.androidView = view; // for workaround, uncomment this line\r\n alertDialog.show();\r\n});\r\nwin.add(button);\r\nwin.open();\r\n{code}", "attachment": [], "flagged": false, "summary": "Android: NullPointerException when reusing an AlertDialog that contains an androidView", "creator": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "pegli", "key": "pegli", "displayName": "Paul Mietz Egli", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "OSX 10.8.4, Titanium SDK 3.1.1.GA, Android SDK r22.0.1", "comment": { "comments": [ { "id": "261174", "author": { "name": "clathrop", "key": "clathrop", "displayName": "Carter Lathrop", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Tested and confirmed on:\nAndroid GS3 4.1.2\nTi 3.1.1GA\n", "updateAuthor": { "name": "clathrop", "key": "clathrop", "displayName": "Carter Lathrop", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-07-09T22:26:24.000+0000", "updated": "2013-07-09T22:26:24.000+0000" }, { "id": "261584", "author": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "body": "PR:-\r\nhttps://github.com/appcelerator/titanium_mobile/pull/4451", "updateAuthor": { "name": "bijuexalture", "key": "bijuexalture", "displayName": "Biju pm", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-07-12T04:54:57.000+0000", "updated": "2013-07-12T04:54:57.000+0000" }, { "id": "275907", "author": { "name": "pmishra", "key": "pmishra", "displayName": "Paras Mishra", "active": true, "timeZone": "Asia/Kolkata" }, "body": "AlertDialog is working fine when contains an androidView. No error occurs.\r\n\r\nVerified Fix on:\r\nDevice : Google Nexus 7, Android Version: 4.3\r\nSDK: 3.2.0.v20131018154951\r\nCLI version : 3.2.0\r\nOS : MAC OSX 10.8.4\r\nAlloy : 1.2.2\r\nAppcelerator Studio, build: 3.2.0.201310181700\r\nXCode : 5", "updateAuthor": { "name": "pmishra", "key": "pmishra", "displayName": "Paras Mishra", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-10-21T10:19:18.000+0000", "updated": "2013-10-21T10:19:18.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }