Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12204] Crash when accessing ActionBar on non-ActionBar window

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-02-21T18:34:42.000+0000
Affected Version/sRelease 3.0.0
Fix Version/s2013 Sprint 04 API, 2013 Sprint 04
ComponentsAndroid
Labelsapi
ReporterArthur Evans
AssigneePing Wang
Created2013-01-03T22:10:21.000+0000
Updated2017-03-21T21:58:21.000+0000

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.

Comments

  1. Arthur Evans 2013-01-04

    Reproduced on master as well.
  2. Arthur Evans 2013-01-04

    These issues both show the same error: Unable to lookup Proxy.prototype.setProperty Not sure if this is significant or not.
  3. Arthur Evans 2013-01-09

    Further notes. I tried this on the single-window template with the same results. After some experimentation, it appears that this crash was caused by trying to access the action bar when the current window DOESN'T have an action bar theme -- for example, because the window was created as translucent or with modal: true. Accordingly, I'm going to knock down the severity a little, but this is still an uncatchable exception. In this case, we should either throw a JS exception or simply return undefined for the actionBar property, so the user can handle the case appropriately. As it stands, I don't think there's any way for the user to test whether the current window supports an action bar.
  4. Ping Wang 2013-02-21

    Cannot reproduce with the latest master.
  5. Chris Rose 2013-10-16

    I can reproduce this in 3.1.3, when a window is opened with modal: true. I'll attach a test case.
  6. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced and due to the above comments.

JSON Source