2015-04-24 89 views
1

首先:一切工作完全按照預期的iOS中。鈦的Android應用程序崩潰,在更新ScrollableView

我相信這個問題是一些由鈦生成的Java對象沒有得到一個參數來更新可滾動視圖的大小。

錯誤日誌:

[WARN] : ResourceType: No known package when getting name for resource  number 0xffffffff 
[WARN] : dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4d57b20) 
[ERROR] : TiApplication: (main) [674,5584] Sending event: exception on thread: main msg:java.lang.IllegalStateException: The application's PagerAdapter changed the 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: The application's PagerAdapter changed the 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: at android.support.v4.view.ViewPager.populate(ViewPager.java:962) 
[ERROR] : TiApplication: at android.support.v4.view.ViewPager.populate(ViewPager.java:914) 
[ERROR] : TiApplication: at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.constrainChild(TiCompositeLayout.java:398) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onMeasure(TiCompositeLayout.java:278) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.constrainChild(TiCompositeLayout.java:398) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onMeasure(TiCompositeLayout.java:278) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.constrainChild(TiCompositeLayout.java:398) 
[ERROR] : TiApplication: at org.appcelerator.titanium.view.TiCompositeLayout.onMeasure(TiCompositeLayout.java:278) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
[ERROR] : TiApplication: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
[ERROR] : TiApplication: at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:327) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125) 
[ERROR] : TiApplication: at android.widget.FrameLayout.onMeasure(FrameLayout.java:310) 
[ERROR] : TiApplication: at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291) 
[ERROR] : TiApplication: at android.view.View.measure(View.java:16497) 
[ERROR] : TiApplication: at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912) 
[ERROR] : TiApplication: at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109) 
[ERROR] : TiApplication: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291) 
[ERROR] : TiApplication: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996) 
[ERROR] : TiApplication: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600) 
[ERROR] : TiApplication: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761) 
[ERROR] : TiApplication: at android.view.Choreographer.doCallbacks(Choreographer.java:574) 
[ERROR] : TiApplication: at android.view.Choreographer.doFrame(Choreographer.java:544) 
[ERROR] : TiApplication: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747) 
[ERROR] : TiApplication: at android.os.Handler.handleCallback(Handler.java:733) 
[ERROR] : TiApplication: at android.os.Handler.dispatchMessage(Handler.java:95) 
[ERROR] : TiApplication: at android.os.Looper.loop(Looper.java:136) 
[ERROR] : TiApplication: at android.app.ActivityThread.main(ActivityThread.java:5001) 
[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:785) 
[ERROR] : TiApplication: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
[ERROR] : TiApplication: at dalvik.system.NativeStart.main(Native Method) 
[INFO] : Process: Sending signal. PID: 1280 SIG: 9 

當直接設置可滾動視圖的.views屬性或使用.setViews時()碰撞發生的情況。

相關代碼:

//on scrolling of the Years view fill the makes and 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 the selected year (aka the label w/ the 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 an array of strings 

     for(var i = 0; i < 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(); 
} 

和:

//populate model when year/make is 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 the selected year (aka the label w/ the 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 i = 0; i < 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); //<--- this is the 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(); 
} 

當相應的滾動視圖滾動這些事件被觸發。

每個可滾動視圖都是在xml視圖中創建的。

回答

0

我發現我自己的問題:

爲什麼這發生是由於我自己的removeAllChildren功能不能正常工作的原因。由於鈦的功能不起作用,我不得不創建自己的。

函數的內部看起來是這樣的:

$.scrollableView.values = []; //an empty array 

相反,我使用以下代碼:

//Remove old data from $.makeScrollableView 
$.makeScrollableView.setCurrentPage(0); 
makeViews.length = 0; 

當前索引設置爲0,然後將數組的長度設定爲0解決我的問題。

0

@ starlord7,你在你的代碼有以下說法是不正確的......

removeAllChildren($.makeScrollableView); 

你必須改變它......

$.makeScrollableView.removeAllChildren(); 

而且,我不是完全肯定,如果它只是設置makeViews數組的長度爲0。如果您有需要被釋放的看法提供一些參考是個好主意,然後將被清理一個消滅他們一個。這可以幫助你釋放資源,如視頻,音頻,大型圖片事件監聽器,參照其它視圖等

請記住,這是很容易使用鈦造成巨大的內存泄漏的Android。