Problem
The [Titanium.UI.Picker.add](
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Picker.add-method.html) method causes an exception when used to add columns.
Note: this works as expected on iOS. Also note that adding rows also needs to be tested.
Test case
var win = Ti.UI.createWindow({
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false,
title: 'Use picker to make selection'
});
var fruit = [ 'Bananas', 'Grapes', 'Blueberries', 'Strawberries' ];
var color = [ 'blue', 'red', 'yellow', 'white' ];
var column1 = Ti.UI.createPickerColumn();
for(var i=0, ilen=fruit.length; i<ilen; i++){
var row = Ti.UI.createPickerRow({
title: fruit[i]
});
column1.addRow(row);
}
var column2 = Ti.UI.createPickerColumn();
for(var i=0, ilen=color.length; i<ilen; i++){
var row = Ti.UI.createPickerRow({
title: color[i]
});
column2.addRow(row);
}
var picker = Ti.UI.createPicker({
// columns: [column1, column2], // this works on both platforms
selectionIndicator: true,
useSpinner: true, // required in order to use multi-column pickers with Android
top:50
});
picker.add([column1, column2]); // this only works on ios
function pickerDefaults(obj){
// on iOS, must be after picker has been rendered
picker.setSelectedRow(0, 2, false);
picker.setSelectedRow(1, 3, false);
}
win.add(picker);
var isAndroid = Ti.Platform.osname === 'android';
if(isAndroid){
pickerDefaults(picker);
}
win.open();
if(!isAndroid){
setTimeout(function(){
pickerDefaults(picker);
}, 1500);
}
Logs
368 TiFastDev D (Thread-8) [41726,42143] Execute command: kill
368 TiFastDev W (Thread-8) [0,42143] Killing app from Fastdev server request
368 Process I Sending signal. PID: 368 SIG: 9
60 ActivityManager I Process com.appcelerator.testing10 (pid 368) has died.
60 WindowManager I WIN DEATH: Window{450dde00 com.appcelerator.testing10/org.appcelerator.titanium.TiActivity paused=false}
60 WindowManager I WIN DEATH: Window{4503e840 com.appcelerator.testing10/com.appcelerator.testing10.Testing10Activity paused=true}
60 InputManagerService W Got RemoteException sending setActive(false) notification to pid 368 uid 10036
390 AndroidRuntime D
390 AndroidRuntime D >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
390 AndroidRuntime D CheckJNI is ON
390 AndroidRuntime D --- registering native functions ---
60 ActivityManager I Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.appcelerator.testing10/.Testing10Activity }
60 ActivityManager I Start proc com.appcelerator.testing10 for activity com.appcelerator.testing10/.Testing10Activity: pid=396 uid=10036 gids={1015, 3003}
390 AndroidRuntime D Shutting down VM
390 AndroidRuntime I NOTE: attach of thread 'Binder Thread #3' failed
396 TiApplication I (main) [0,0] checkpoint, app created.
396 TiApplication I (main) [214,214] Titanium 1.8.1 (2012/01/27 17:31 a24502a)
396 TiFastDev D (main) [147,361] Enabling Fastdev on port 50442
396 TiFastDev D (main) [10,371] sent tokens successfully
396 TiFastDev D (main) [2,373] Fastdev session handshake succesful.
396 TiApplication I (main) [5,378] Titanium Javascript runtime: v8
396 TiApplication W (main) [42,420] activity stack is emtpy, unable to get current activity
396 TiRootActivity I (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
396 TiApplication W (main) [91,91] activity stack is emtpy, unable to get current activity
396 TiApplication W (main) [1,92] activity stack is emtpy, unable to get current activity
396 TiApplication W (main) [1,93] activity stack is emtpy, unable to get current activity
396 TiApplication E (KrollRuntimeThread) [971,1064] APP PROXY: ti.modules.titanium.app.AppModule@44f5c9e8
396 TiAssetHelper D Fetching "app.js" with Fastdev...
60 NotificationService W Object died trying to hide notification android.app.ITransientNotification$Stub$Proxy@44f810a8 in package com.appcelerator.testing10
60 ActivityManager W setProcessForeground called on unknown pid: 368
396 PickerColumnProxy W Unexpected type not added to picker column: ti.modules.titanium.ui.PickerColumnProxy
396 PickerColumnProxy W Unexpected type not added to picker column: ti.modules.titanium.ui.PickerColumnProxy
60 ActivityManager I Starting activity: Intent { cmp=com.appcelerator.testing10/org.appcelerator.titanium.TiActivity (has extras) }
396 TiRootActivity I (main) [0,0] checkpoint, on root activity resume. activity = com.appcelerator.testing10.Testing10Activity@44f01ce8
60 ActivityManager I Displayed activity com.appcelerator.testing10/org.appcelerator.titanium.TiActivity: 241 ms (total 3383 ms)
396 AndroidRuntime D Shutting down VM
396 TiApplication E (main) [363,363] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 1.8.1,2012/01/27 17:31,a24502a
396 TiApplication E java.lang.NullPointerException
396 TiApplication E at java.util.Arrays$ArrayList.<init>(Arrays.java:49)
396 TiApplication E at java.util.Arrays.asList(Arrays.java:171)
396 TiApplication E at ti.modules.titanium.ui.widget.picker.TextWheelAdapter.<init>(TextWheelAdapter.java:28)
396 TiApplication E at ti.modules.titanium.ui.widget.picker.TiUISpinnerColumn.refreshNativeView(TiUISpinnerColumn.java:180)
396 TiApplication E at ti.modules.titanium.ui.widget.picker.TiUISpinnerColumn.<init>(TiUISpinnerColumn.java:38)
396 TiApplication E at ti.modules.titanium.ui.PickerColumnProxy.createView(PickerColumnProxy.java:219)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:448)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:434)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:471)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:456)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:434)
396 TiApplication E at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:471)
396 TiApplication E at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:81)
396 TiApplication E at android.os.Handler.dispatchMessage(Handler.java:95)
396 TiApplication E at android.os.Looper.loop(Looper.java:123)
396 TiApplication E at android.app.ActivityThread.main(ActivityThread.java:4627)
396 TiApplication E at java.lang.reflect.Method.invokeNative(Native Method)
396 TiApplication E at java.lang.reflect.Method.invoke(Method.java:521)
396 TiApplication E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
396 TiApplication E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
396 TiApplication E at dalvik.system.NativeStart.main(Native Method)
396 AndroidRuntime E FATAL EXCEPTION: main
396 AndroidRuntime E java.lang.NullPointerException
396 AndroidRuntime E at java.util.Arrays$ArrayList.<init>(Arrays.java:49)
396 AndroidRuntime E at java.util.Arrays.asList(Arrays.java:171)
396 AndroidRuntime E at ti.modules.titanium.ui.widget.picker.TextWheelAdapter.<init>(TextWheelAdapter.java:28)
396 AndroidRuntime E at ti.modules.titanium.ui.widget.picker.TiUISpinnerColumn.refreshNativeView(TiUISpinnerColumn.java:180)
396 AndroidRuntime E at ti.modules.titanium.ui.widget.picker.TiUISpinnerColumn.<init>(TiUISpinnerColumn.java:38)
396 AndroidRuntime E at ti.modules.titanium.ui.PickerColumnProxy.createView(PickerColumnProxy.java:219)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:448)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:434)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:471)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:456)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:434)
396 AndroidRuntime E at org.appcelerator.titanium.proxy.TiViewProxy.realizeViews(TiViewProxy.java:471)
396 AndroidRuntime E at ti.modules.titanium.ui.ActivityWindowProxy.handleMessage(ActivityWindowProxy.java:81)
396 AndroidRuntime E at android.os.Handler.dispatchMessage(Handler.java:95)
396 AndroidRuntime E at android.os.Looper.loop(Looper.java:123)
396 AndroidRuntime E at android.app.ActivityThread.main(ActivityThread.java:4627)
396 AndroidRuntime E at java.lang.reflect.Method.invokeNative(Native Method)
396 AndroidRuntime E at java.lang.reflect.Method.invoke(Method.java:521)
396 AndroidRuntime E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
396 AndroidRuntime E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
396 AndroidRuntime E at dalvik.system.NativeStart.main(Native Method)
60 ActivityManager W Force finishing activity com.appcelerator.testing10/org.appcelerator.titanium.TiActivity
60 ActivityManager W Force finishing activity com.appcelerator.testing10/.Testing10Activity
60 ActivityManager W Activity pause timeout for HistoryRecord{45050908 com.appcelerator.testing10/org.appcelerator.titanium.TiActivity}
60 ActivityManager W Activity destroy timeout for HistoryRecord{4500a9c8 com.appcelerator.testing10/.Testing10Activity}
60 ActivityManager W Activity destroy timeout for HistoryRecord{45050908 com.appcelerator.testing10/org.appcelerator.titanium.TiActivity}
396 Process I Sending signal. PID: 396 SIG: 9
60 WindowManager I WIN DEATH: Window{450c5888 com.appcelerator.testing10/com.appcelerator.testing10.Testing10Activity paused=true}
60 WindowManager I WIN DEATH: Window{450f4d00 com.appcelerator.testing10/org.appcelerator.titanium.TiActivity paused=false}
60 ActivityManager I Process com.appcelerator.testing10 (pid 396) has died.
Workaround
Use the columns property instead
Issue does not reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 (03/11/13 15:43 0c88429) Titanium SDK version: 3.0.2 (02/07/13 16:46 a4def81) Device: Samsung galaxy s duos Android version: 4.0.4 jithinpv
Closing ticket as the issue cannot be reproduced.