javascript - Titanium Android app crashes upon updating ScrollableView -
first of all: works intended in ios.
the issue believe java object generated titanium isn't getting parameter updates size of scrollable view.
error log:
[warn] : resourcetype: no known package when getting name resource number 0xffffffff [warn] : dalvikvm: threadid=1: thread exiting uncaught exception (group=0xa4d57b20) [error] : tiapplication: (main) [674,5584] sending event: exception on thread: main msg:java.lang.illegalstateexception: application's pageradapter changed adapter's contents without calling pageradapter#notifydatasetchanged! expected adapter item count: 1, found: 0 pager id: ffffffff pager class: class ti.modules.titanium.ui.widget.tiuiscrollableview$1 problematic adapter: class ti.modules.titanium.ui.widget.tiuiscrollableview$viewpageradapter; titanium 3.5.0,2015/01/12 15:33,0014f83 [error] : tiapplication: java.lang.illegalstateexception: application's pageradapter changed adapter's contents without calling pageradapter#notifydatasetchanged! expected adapter item count: 1, found: 0 pager id: ffffffff pager class: class ti.modules.titanium.ui.widget.tiuiscrollableview$1 problematic adapter: class ti.modules.titanium.ui.widget.tiuiscrollableview$viewpageradapter [error] : tiapplication: @ android.support.v4.view.viewpager.populate(viewpager.java:962) [error] : tiapplication: @ android.support.v4.view.viewpager.populate(viewpager.java:914) [error] : tiapplication: @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1436) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.constrainchild(ticompositelayout.java:398) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.onmeasure(ticompositelayout.java:278) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.constrainchild(ticompositelayout.java:398) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.onmeasure(ticompositelayout.java:278) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.constrainchild(ticompositelayout.java:398) [error] : tiapplication: @ org.appcelerator.titanium.view.ticompositelayout.onmeasure(ticompositelayout.java:278) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) [error] : tiapplication: @ android.widget.framelayout.onmeasure(framelayout.java:310) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) [error] : tiapplication: @ com.android.internal.widget.actionbaroverlaylayout.onmeasure(actionbaroverlaylayout.java:327) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:5125) [error] : tiapplication: @ android.widget.framelayout.onmeasure(framelayout.java:310) [error] : tiapplication: @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2291) [error] : tiapplication: @ android.view.view.measure(view.java:16497) [error] : tiapplication: @ android.view.viewrootimpl.performmeasure(viewrootimpl.java:1912) [error] : tiapplication: @ android.view.viewrootimpl.measurehierarchy(viewrootimpl.java:1109) [error] : tiapplication: @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1291) [error] : tiapplication: @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:996) [error] : tiapplication: @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5600) [error] : tiapplication: @ android.view.choreographer$callbackrecord.run(choreographer.java:761) [error] : tiapplication: @ android.view.choreographer.docallbacks(choreographer.java:574) [error] : tiapplication: @ android.view.choreographer.doframe(choreographer.java:544) [error] : tiapplication: @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:747) [error] : tiapplication: @ android.os.handler.handlecallback(handler.java:733) [error] : tiapplication: @ android.os.handler.dispatchmessage(handler.java:95) [error] : tiapplication: @ android.os.looper.loop(looper.java:136) [error] : tiapplication: @ android.app.activitythread.main(activitythread.java:5001) [error] : tiapplication: @ java.lang.reflect.method.invokenative(native method) [error] : tiapplication: @ java.lang.reflect.method.invoke(method.java:515) [error] : tiapplication: @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:785) [error] : tiapplication: @ com.android.internal.os.zygoteinit.main(zygoteinit.java:601) [error] : tiapplication: @ dalvik.system.nativestart.main(native method) [info] : process: sending signal. pid: 1280 sig: 9
the crash happens when either directly setting .views property of scrollable view or when using .setviews().
relevant code:
//on scrolling of years view fill makes , model views function populatemake(e){ $.makescrollableview.scrolltoview(0); removeallchildren($.makescrollableview); //generating url var selectedyear = $.yearscrollableview.currentpage; //selected index var caryearviews = $.yearscrollableview.getviews(); //array of views var children = caryearviews[selectedyear].getchildren(); //children of selected year (aka label w/ year in it) var makeyear = children[0].gettext(); var url = "www.example.com"; var makeviews = []; var client = ti.network.createhttpclient({ onload : function(e){ var yearmakes = []; yearmakes = parsemakes(this.responsetext); //returns array of strings for(var = 0; < yearmakes.length; i++){ var yearlabel = ti.ui.createlabel({ title: "year", text: yearmakes[i] }); var view = ti.ui.createview({ backgroundcolor: 'blue' }); view.add(yearlabel); makeviews.push(view); } $.makescrollableview.setviews(makeviews); //<--- crashes here when scrolling $.yearscrollableview populatemodel(); }, onerror : function (e){ ti.api.error("http error populating makes"); } }); client.open("get", url); client.send(); }
and:
//populate model when year/make changed function populatemodel(e){ $.modelscrollableview.scrolltoview(0); removeallchildren($.modelscrollableview); var selectedyear = $.yearscrollableview.currentpage; //selected index var caryearviews = $.yearscrollableview.getviews(); //array of views var childrenyear = caryearviews[selectedyear].getchildren(); //children of selected year (aka label w/ year in it) var caryear = childrenyear[0].gettext(); var url = "www.totallyafakewebsite.net"; ti.api.info(url); var modelviews = []; var client = ti.network.createhttpclient({ onload : function(e){ var carmodels = []; carmodels = parsemodels(this.responsetext); //array of strings for(var = 0; < carmodels.length; i++){ var modellabel = ti.ui.createlabel({ title: "model", text: carmodels[i] }); var view = ti.ui.createview({ backgroundcolor: 'blue' }); view.add(modellabel); modelviews.push(view); } $.modelscrollableview.setviews(modelviews); //<--- crash when scrolling $.makescrollableview //$.modelscrollableview.views = modelviews; //doesn't work either }, onerror : function (e){ ti.api.error("http error populating models: " + e.error); } }); client.open("get", url); client.send(); }
these events triggered when corresponding scrollable view scrolled.
each scrollable view created in xml view.
i found own issue:
the reason why happening due own removeallchildren function not working. because titanium's function did not work had create own.
the inside of function looked this:
$.scrollableview.values = []; //an empty array
instead used following code:
//remove old data $.makescrollableview $.makescrollableview.setcurrentpage(0); makeviews.length = 0;
setting current index 0 , setting array length 0 resolved issue.
Comments
Post a Comment