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

Crash when accessing ActionBar on non-ActionBar window

    Details

      Description

      I'm creating an application based on the default two-tab app template (the new style, CommonJS one).

      When I try to initialize the home icon click handler in a tab group's open event handler, the app crashes with the following NullPointer exception:

      I/TiAPI   (  686):  Tab group open event.
      E/Proxy   (  686): Unable to lookup Proxy.prototype.setProperty
      I/Process (   76): Sending signal. PID: 686 SIG: 3
      I/dalvikvm(  686): threadid=3: reacting to signal 3
      I/dalvikvm(  686): Wrote stack traces to '/data/anr/traces.txt'
      D/AndroidRuntime(  686): Shutting down VM
      W/dalvikvm(  686): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
      E/TiApplication(  686): (main) [643,643] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.0.0,2012/12/12 18:49,a5894b3
      E/TiApplication(  686): java.lang.NullPointerException
      E/TiApplication(  686): 	at org.appcelerator.titanium.proxy.ActionBarProxy.handleMessage(ActionBarProxy.java:222)
      E/TiApplication(  686): 	at android.os.Handler.dispatchMessage(Handler.java:95)
      E/TiApplication(  686): 	at android.os.Looper.loop(Looper.java:137)
      E/TiApplication(  686): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
      E/TiApplication(  686): 	at java.lang.reflect.Method.invokeNative(Native Method)
      E/TiApplication(  686): 	at java.lang.reflect.Method.invoke(Method.java:511)
      E/TiApplication(  686): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
      E/TiApplication(  686): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
      E/TiApplication(  686): 	at dalvik.system.NativeStart.main(Native Method)
      E/AndroidRuntime(  686): FATAL EXCEPTION: main
      E/AndroidRuntime(  686): java.lang.NullPointerException
      E/AndroidRuntime(  686): 	at org.appcelerator.titanium.proxy.ActionBarProxy.handleMessage(ActionBarProxy.java:222)
      E/AndroidRuntime(  686): 	at android.os.Handler.dispatchMessage(Handler.java:95)
      E/AndroidRuntime(  686): 	at android.os.Looper.loop(Looper.java:137)
      E/AndroidRuntime(  686): 	at android.app.ActivityThread.main(ActivityThread.java:4424)
      E/AndroidRuntime(  686): 	at java.lang.reflect.Method.invokeNative(Native Method)
      E/AndroidRuntime(  686): 	at java.lang.reflect.Method.invoke(Method.java:511)
      E/AndroidRuntime(  686): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
      E/AndroidRuntime(  686): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
      E/AndroidRuntime(  686): 	at dalvik.system.NativeStart.main(Native Method)
      W/ActivityManager(   76):   Force finishing activity com.appcelerator.actionbardemo/org.appcelerator.titanium.TiActivity
      W/WindowManager(   76): Failure taking screenshot for (180x273) to layer 21020
      W/ActivityManager(   76):   Force finishing activity com.appcelerator.actionbardemo/.ActionbardemoActivity
      

      Test code:

      Create a new application using the Tabbed Application template.

      Add the following code to ui/common/ApplicationTabGroup.js after the line `self.addTab(tab2);`:

      	if (Ti.Platform.name === 'android') {
      		Ti.API.info("Android");
      		self.addEventListener('open', function(e) {
      			Ti.API.info("Tab group open event.");
      			var activity, actionBar;
      			activity = self.getActivity();
      			var view = Ti.UI.createImageView({
      				backgroundColor : "red",
      				image : "images/random_icon.png",
      				width : 60,
      				height : 60
      			});
      			activity.onCreateOptionsMenu = function(e) {
      				var item, menu;
      				menu = e.menu;
      				menu.clear();
      				if (tg.activeTab == tab1) {
      					item = menu.add({
      						title : 'Search',
      						icon : "images/random_icon.png", // (Ti.Android.R.drawable.ic_menu_search ? Ti.Android.R.drawable.ic_menu_search : Ti.App.Android.R.drawable.appicon),
      						showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
      					});
      				}
      				item = menu.add({
      					title : "Text Item",
      					icon : 'KS-nav_icon.png',
      					showAsAction : Ti.Android.SHOW_AS_ACTION_IF_ROOM | Ti.Android.SHOW_AS_ACTION_WITH_TEXT
      				});
      			}
      			try {
      				actionBar = activity.actionBar;
      				if (actionBar) {
      					actionBar.onHomeIconItemSelected = function() {
      						Ti.API.info("Home clicked");
      					};
      				}
      			} catch(exception) {
      				Ti.API.error("Couldn't home icon selected handler.");
      			}
      		});
      	}
      

      And update the `tiapp.xml` so that you can use the action bar:

          <android xmlns:android="http://schemas.android.com/apk/res/android">
              <tool-api-level>16</tool-api-level>
              <manifest>
                  <uses-sdk android:targetSdkVersion="11"/>
                  <!-- other manifest entries -->
              </manifest>
          </android>
      

      When I use the same code in a non-commonJS project, it doesn't crash.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pwang Ping Wang
                Reporter:
                aevans Arthur Evans
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Integration