好的,所以我在我的程序中有这个方法,我从ArrayList中删除了一个对象。 (该方法位于本文的底部)。它还做了一些其他的东西,但经过调试很多我发现这条线导致程序崩溃:
myTrackedEventsList.remove(currentEvent);
我通过尝试使用和不使用此行来运行块来测试它。如果没有这条线,它就不会崩溃。 有趣的是,该行不会直接导致程序崩溃,实际上整个方法都会运行,并且它会回到我调用它的地方,这是我的
public void onClick(View v) {}
退出onClick方法后,它跳转到
Activity.java -> View.java -> ActivityThread.jaca -> Handler.java and Looper.java
现在,我真的不知道这些类会做什么,我不知道为什么它们导致我的程序崩溃......这是ActivityThread.java导致程序崩溃。
你能帮我弄清楚程序崩溃的原因吗? =)
非常感谢您的帮助! 所有代码都可以在这里找到: https://github.com/smholsen/BigDayCountdown/tree/master/app/src/main/java/com/simonm/bigdaycountdown
这是我得到的错误代码:
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: FATAL EXCEPTION: main
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: Process: com.simonm.bigdaycountdown, PID: 17346
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.AbsListView.obtainView(AbsListView.java:2344)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ListView.makeAndAddView(ListView.java:1864)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ListView.fillDown(ListView.java:698)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ListView.fillFromTop(ListView.java:759)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.ListView.layoutChildren(ListView.java:1673)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.AbsListView.onLayout(AbsListView.java:2148)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1067)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.widget.FrameLayout.onLayout(FrameLayout.java:508)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.View.layout(View.java:15691)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewGroup.layout(ViewGroup.java:4967)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2093)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1850)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1063)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5807)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.Choreographer.doCallbacks(Choreographer.java:580)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.Choreographer.doFrame(Choreographer.java:550)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:739)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.os.Looper.loop(Looper.java:135)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5321)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:372)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
12-03 21:04:08.365 17346-17346/com.simonm.bigdaycountdown E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
12-03 21:04:08.459 17346-17346/com.simonm.bigdaycountdown I/Process: Sending signal. PID: 17346 SIG: 9
这是deleteEvent()方法:
protected void deleteEvent(){
if (currentEvent != null) {
eventNames.remove(currentEvent.getEventTitle());
//TODO: This line somehow crashes the program long after it has been executed, I have no idea why.
myTrackedEventsList.remove(currentEvent);
currentEvent.delete();
currentEvent = null;
Collections.sort(myTrackedEventsList);
if (myTrackedEventsList.size() > 0){
currentEvent = myTrackedEventsList.get(0);
updateUI();
}
updateEventDrawer();
}
if (myTrackedEventsList.size() == 0){
resetUI();
updateEventDrawer();
noEventsUI();
findViewById(R.id.getStartedText).setVisibility(View.VISIBLE);
((ImageView) findViewById(R.id.background)).setImageResource(R.mipmap.background);
}
}
答案 0 :(得分:1)
看起来你的myTrackedEventsList为null。检查您向该阵列添加数据的位置,并确保您正在填写该数据。
答案 1 :(得分:1)
它可能是由Log.i引起的(someString,null);
String.valueOf(null) //return null
Log.i("eventListBEFORE", String.valueOf(myTrackedEventsList));