Problem Description
On Android searching with a SearchView attached to a listview that uses templates causes the app to crash.
Works fine on iOS and interestingly on Genymotion S5 emulator. But crashes on device. The error log is below.
Maybe related to this forum post [
https://developer.appcelerator.com/question/173280/search-alloy-collection-in-listview-using-template]
Test Case
1. Create a new mobile project ( Classic Titanium )
2. Copy this code into app.js
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var myTemplate = {
childTemplates: [
{
type: 'Ti.UI.ImageView',
bindId: 'pic',
properties: {
width: '50dp', height: '50dp', left: 0
}
},
{
type: 'Ti.UI.Label',
bindId: 'info',
properties: {
color: 'black',
font: { fontFamily:'Arial', fontSize: '20dp', fontWeight:'bold' },
left: '60dp', top: 0,
}
},
{
type: 'Ti.UI.Label',
bindId: 'es_info',
properties: {
color: 'gray',
font: { fontFamily:'Arial', fontSize: '14dp' },
left: '60dp', top: '25dp',
}
}
]
};
search = Ti.UI.Android.createSearchView({
hintText: "Table Search"
});
var listView = Ti.UI.createListView({
templates: { 'template': myTemplate },
defaultItemTemplate: 'template',
searchView:search
});
var sections = [];
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits / Frutas'});
var fruitDataSet = [
{ info: {text: 'Apple'}, es_info: {text: 'Manzana'}, pic: {image: 'apple.png'}},
{ info: {text: 'Banana'}, es_info: {text: 'Banana'}, pic: {image: 'banana.png'}}
];
fruitSection.setItems(fruitDataSet);
sections.push(fruitSection);
var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables / Verduras'});
var vegDataSet = [
{ info: {text: 'Carrot'}, es_info: {text: 'Zanahoria'}, pic: {image: 'carrot.png'}},
{ info: {text: 'Potato'}, es_info: {text: 'Patata'}, pic: {image: 'potato.png'}}
];
vegSection.setItems(vegDataSet);
sections.push(vegSection);
var grainSection = Ti.UI.createListSection({ headerTitle: 'Grains / Granos'});
var grainDataSet = [
{ info: {text: 'Corn'}, es_info: {text: 'Maiz'}, pic: {image: 'corn.png'}},
{ info: {text: 'Rice'}, es_info: {text: 'Arroz'}, pic: {image: 'rice.png'}}
];
grainSection.setItems(grainDataSet);
sections.push(grainSection);
listView.setSections(sections);
win.add(listView);
win.open();
3. Run it on a device
4. Click on the search
Actual Results
The app will crash
Expected results
The app working fine.
Extra info
{panel:title=Error log}
[ERROR] TiApplication: (main) [2475,185914] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.3.0,2014/07/11 12:36,787cd39
[ERROR] TiApplication: java.lang.NullPointerException
[ERROR] TiApplication: at ti.modules.titanium.ui.widget.listview.ListSectionProxy.applyFilter(ListSectionProxy.java:935)
[ERROR] TiApplication: at ti.modules.titanium.ui.widget.listview.TiListView.reFilter(TiListView.java:543)
[ERROR] TiApplication: at ti.modules.titanium.ui.widget.listview.TiListView.filterBy(TiListView.java:851)
[ERROR] TiApplication: at ti.modules.titanium.ui.widget.searchview.TiUISearchView.onQueryTextChange(TiUISearchView.java:90)
[ERROR] TiApplication: at android.support.v7.widget.SearchView.onTextChanged(SearchView.java:1118)
[ERROR] TiApplication: at android.support.v7.widget.SearchView.access$2000(SearchView.java:103)
[ERROR] TiApplication: at android.support.v7.widget.SearchView$12.onTextChanged(SearchView.java:1578)
[ERROR] TiApplication: at android.widget.TextView.sendOnTextChanged(TextView.java:8905)
[ERROR] TiApplication: at android.widget.TextView.handleTextChanged(TextView.java:8979)
[ERROR] TiApplication: at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:11160)
[ERROR] TiApplication: at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:964)
[ERROR] TiApplication: at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:498)
[ERROR] TiApplication: at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:437)
[ERROR] TiApplication: at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:30)
[ERROR] TiApplication: at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:679)
[ERROR] TiApplication: at android.view.inputmethod.BaseInputConnection.setComposingText(BaseInputConnection.java:437)
[ERROR] TiApplication: at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:333)
[ERROR] TiApplication: at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
[ERROR] TiApplication: at android.os.Handler.dispatchMessage(Handler.java:102)
[ERROR] TiApplication: at android.os.Looper.loop(Looper.java:136)
[ERROR] TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5579)
[ERROR] TiApplication: at java.lang.reflect.Method.invokeNative(Native Method)
[ERROR] TiApplication: at java.lang.reflect.Method.invoke(Method.java:515)
[ERROR] TiApplication: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
[ERROR] TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
[ERROR] TiApplication: at dalvik.system.NativeStart.main(Native Method)
{panel}
Closing ticket as I am unable to reproduce the issue using the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80