Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7000] Android: UI - crash when window property not initialized on tab creation

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-01-17T21:43:15.000+0000
Affected Version/sn/a
Fix Version/sSprint 2012-02, Release 2.0.0, Release 1.8.1
ComponentsAndroid
Labelsmodule_tabgroup, qe-testadded, regression
ReporterBenjamin Jeanjean
AssigneeOpie Cyrus
Created2012-01-05T09:28:15.000+0000
Updated2013-12-10T05:58:31.000+0000

Description

Problem

If the window property is omitted when a [Titanium.UI.Tab](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Tab-object#properties) is created, despite setting it directly afterwards with the setWindow() method, it will cause the app to crash. The crash will occur when the open method is called on the TabGroup.

Test case

Ti.UI.setBackgroundColor('#000');

var tabGroup = Ti.UI.createTabGroup();

var win1 = Ti.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Ti.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
});
tab1.window = win1;

var win2 = Ti.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Ti.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
});
tab2.setWindow(win2);

tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  

tabGroup.open();

Logs

01-05 17:59:57.370: ERROR/TiApplication(6157): (main) [1,4512] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 1.8.0.1,2011/12/22 13:09,fbdc96f
01-05 17:59:57.370: ERROR/TiApplication(6157): java.lang.NullPointerException
01-05 17:59:57.370: ERROR/TiApplication(6157):     at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:204)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:314)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:95)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at android.os.Handler.dispatchMessage(Handler.java:95)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at android.os.Looper.loop(Looper.java:123)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at android.app.ActivityThread.main(ActivityThread.java:3691)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at java.lang.reflect.Method.invoke(Method.java:507)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
01-05 17:59:57.370: ERROR/TiApplication(6157):     at dalvik.system.NativeStart.main(Native Method)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157): FATAL EXCEPTION: main
01-05 17:59:57.400: ERROR/AndroidRuntime(6157): java.lang.NullPointerException
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:204)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at ti.modules.titanium.ui.TabGroupProxy.handlePostOpen(TabGroupProxy.java:314)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at ti.modules.titanium.ui.TabGroupProxy.handleMessage(TabGroupProxy.java:95)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at android.os.Handler.dispatchMessage(Handler.java:95)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at android.os.Looper.loop(Looper.java:123)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at android.app.ActivityThread.main(ActivityThread.java:3691)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at java.lang.reflect.Method.invokeNative(Native Method)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at java.lang.reflect.Method.invoke(Method.java:507)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
01-05 17:59:57.400: ERROR/AndroidRuntime(6157):     at dalvik.system.NativeStart.main(Native Method)

Comments

  1. Benjamin Jeanjean 2012-01-05

    This work on SDK 1.7.5, that's a regression.
  2. Eric Merriman 2012-01-19

    Verified fixed with SDK 1.9.0.v20120119131634 on Nexus S (2.3.6) and Emulator.
  3. Wilson Luu 2012-02-02

    updated labels
  4. Shameer Jan 2013-12-10

    Anvil testcase PR https://github.com/appcelerator/titanium_mobile/pull/5074

JSON Source