我有一个这样的标签式 Android 应用程序:
前两个选项卡包含空视图,第三个包含一个表格视图。
我向它添加了一个事件侦听器(在自定义事件上),并且每次触发事件时我都会实时更新他的内容。
var tb;
function update(){
tb.setData([]);
var row = [];
var r = Titanium.UI.createTableViewRow();
row.push(r);
tb.setData(row);
return true;
}
function MainView() {
self = new ui.View();
tb = Titanium.UI.createTableView({
scrollable: false,
showVerticalScrollIndicator: false,
top: 10,
width: "98%",
//height: perH(0.95) - baseH,
border: 1,
borderColor: "gray",
borderRadius: 6,
});
self.add(tb);
// And i add an event listener to call the update function
Ti.App.addEventListener( 'updateFav', update );
return self;
}
module.exports = MainView;
每次我触发事件时,tableview 都会正常更新,并且一切正常。
但是,如果我点击第一个选项卡,然后转到第二个或第三个选项卡,应用程序就会崩溃!“已停止”是 Android 显示的消息。
logcat 说“NullPointer 异常”,但我不知道为什么!
再次:问题只是将当前选项卡表单更改为第二个或第三个!仅从第二个更改为第三个或反之亦然不会出现问题!!!!
有什么建议吗?
这是错误:
[WARN][dalvikvm( 2070)] threadid=1: thread exiting with uncaught exception (group=0xb1f48648)
[ERROR][TiApplication( 2070)] (main) [42854,169668] Sending event: exception on thread: main msg:java.lang.NullPointerException; Titanium 3.1.3,2013/09/18 12:01,222f4d1
[ERROR][TiApplication( 2070)] java.lang.NullPointerException
[ERROR][TiApplication( 2070)] at android.view.ViewConfiguration.get(ViewConfiguration.java:318)
[ERROR][TiApplication( 2070)] at android.view.View.<init>(View.java:3264)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.<init>(ViewGroup.java:448)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.TiImageView.<init>(TiImageView.java:63)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.TiUIImageView.<init>(TiUIImageView.java:94)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.ImageViewProxy.createView(ImageViewProxy.java:43)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:452)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:438)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.forceCreateView(TiViewProxy.java:406)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.createControls(TiTableViewRowProxyItem.java:246)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:408)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:90)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:229)
[ERROR][TiApplication( 2070)] at android.widget.AbsListView.obtainView(AbsListView.java:2177)
[ERROR][TiApplication( 2070)] at android.widget.ListView.makeAndAddView(ListView.java:1840)
[ERROR][TiApplication( 2070)] at android.widget.ListView.fillDown(ListView.java:675)
[ERROR][TiApplication( 2070)] at android.widget.ListView.fillFromTop(ListView.java:736)
[ERROR][TiApplication( 2070)] at android.widget.ListView.layoutChildren(ListView.java:1655)
[ERROR][TiApplication( 2070)] at android.widget.AbsListView.onLayout(AbsListView.java:2012)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][TiApplication( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableView.onLayout(TiTableView.java:572)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1388)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
[ERROR][TiApplication( 2070)] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
[ERROR][TiApplication( 2070)] at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][TiApplication( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][TiApplication( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][TiApplication( 2070)] at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
[ERROR][TiApplication( 2070)] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
[ERROR][TiApplication( 2070)] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
[ERROR][TiApplication( 2070)] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
[ERROR][TiApplication( 2070)] at android.view.Choreographer$CallbackRecord.run(Choreographer.j
[ERROR][AndroidRuntime( 2070)] FATAL EXCEPTION: main
[ERROR][AndroidRuntime( 2070)] java.lang.NullPointerException
[ERROR][AndroidRuntime( 2070)] at android.view.ViewConfiguration.get(ViewConfiguration.java:318)
[ERROR][AndroidRuntime( 2070)] at android.view.View.<init>(View.java:3264)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.<init>(ViewGroup.java:448)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.TiImageView.<init>(TiImageView.java:63)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.TiUIImageView.<init>(TiUIImageView.java:94)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.ImageViewProxy.createView(ImageViewProxy.java:43)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.handleGetView(TiViewProxy.java:452)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.getOrCreateView(TiViewProxy.java:438)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.proxy.TiViewProxy.forceCreateView(TiViewProxy.java:406)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.createControls(TiTableViewRowProxyItem.java:246)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:408)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableViewRowProxyItem.setRowData(TiTableViewRowProxyItem.java:90)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:229)
[ERROR][AndroidRuntime( 2070)] at android.widget.AbsListView.obtainView(AbsListView.java:2177)
[ERROR][AndroidRuntime( 2070)] at android.widget.ListView.makeAndAddView(ListView.java:1840)
[ERROR][AndroidRuntime( 2070)] at android.widget.ListView.fillDown(ListView.java:675)
[ERROR][AndroidRuntime( 2070)] at android.widget.ListView.fillFromTop(ListView.java:736)
[ERROR][AndroidRuntime( 2070)] at android.widget.ListView.layoutChildren(ListView.java:1655)
[ERROR][AndroidRuntime( 2070)] at android.widget.AbsListView.onLayout(AbsListView.java:2012)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][AndroidRuntime( 2070)] at ti.modules.titanium.ui.widget.tableview.TiTableView.onLayout(TiTableView.java:572)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1388)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at org.appcelerator.titanium.view.TiCompositeLayout.onLayout(TiCompositeLayout.java:578)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)
[ERROR][AndroidRuntime( 2070)] at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)
[ERROR][AndroidRuntime( 2070)] at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
[ERROR][AndroidRuntime( 2070)] at android.view.View.layout(View.java:14289)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewGroup.layout(ViewGroup.java:4562)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1976)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1730)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1004)
[ERROR][AndroidRuntime( 2070)] at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5481)
[ERROR][AndroidRuntime( 2070)] at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
[ERROR][AndroidRuntime( 2070)] at android.view.Choreographer.doCallbacks(Choreographer.java:562)
[ERROR][AndroidRuntime( 2070)] at android.view.Choreographer.doFrame(C