1
由於某種原因,我的應用程序在super.onCreate
中發生nullPointerException異常。 其擴展fragmentActivity的活動。FragmentActivity在onStart中崩潰
public class LiveMatchActivity extends FragmentActivity
這就是我在onStart():
@Override
protected void onStart() {
super.onStart();
Analytics.getIntance().trackStart(this);
}
當我到達super.onStart()
應用壓碎。
這就是日誌:
05-20 11:22:42.735: E/Crittercism(29328): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ftbpro.app/com.ftbpro.app.LiveMatchActivity}: java.lang.NullPointerException
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread.access$600(ActivityThread.java:140)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
05-20 11:22:42.735: E/Crittercism(29328): at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 11:22:42.735: E/Crittercism(29328): at android.os.Looper.loop(Looper.java:137)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread.main(ActivityThread.java:4898)
05-20 11:22:42.735: E/Crittercism(29328): at java.lang.reflect.Method.invokeNative(Native Method)
05-20 11:22:42.735: E/Crittercism(29328): at java.lang.reflect.Method.invoke(Method.java:511)
05-20 11:22:42.735: E/Crittercism(29328): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
05-20 11:22:42.735: E/Crittercism(29328): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
05-20 11:22:42.735: E/Crittercism(29328): at dalvik.system.NativeStart.main(Native Method)
05-20 11:22:42.735: E/Crittercism(29328): Caused by: java.lang.NullPointerException
05-20 11:22:42.735: E/Crittercism(29328): at com.ftbpro.app.EventsFragment.filterAndSortEventsList(EventsFragment.java:211)
05-20 11:22:42.735: E/Crittercism(29328): at com.ftbpro.app.EventsFragment.onCreateView(EventsFragment.java:57)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861)
05-20 11:22:42.735: E/Crittercism(29328): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
05-20 11:22:42.735: E/Crittercism(29328): at com.ftbpro.app.LiveMatchActivity.onStart(LiveMatchActivity.java:77)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.Activity.performStart(Activity.java:5216)
05-20 11:22:42.735: E/Crittercism(29328): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2073)
05-20 11:22:42.735: E/Crittercism(29328): ... 11 more
private void filterAndSortEventsList(LiveMatchDetails liveMatchDetailsToSort) {
List<Event> eventsList = new ArrayList<Event>();
Event gameStartedEvent = null;
Event gameEndedEvent = null;
for (Event event : liveMatchDetailsToSort.getEventsList()) {
if (event.getEvent().equals(Event.YELOW_CARD)
|| event.getEvent().equals(Event.YELOW_CARD2)
|| event.getEvent().contains(Event.GOAL)
|| event.getEvent().equals(Event.RED_CARD)) {
eventsList.add(event);
}
if (event.getExtObjType().equals(GAME_STARTED_OR_ENDED)) {
if (event.getMinute() == 0) {
gameStartedEvent = event;
} else if (event.getMinute() == 90) {
gameEndedEvent = event;
}
}
}
Collections.sort(eventsList);
if (gameEndedEvent != null) {
eventsList.add(0, gameEndedEvent);
}
eventsList.add(gameStartedEvent);
liveMatchDetailsToSort.setEventsList(eventsList);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.events_fragments, container,
false);
TypefaceManager.getInstance(getActivity())
.assignTypeface(getActivity());
events = ((LiveMatchActivity) getActivity()).getEvents();
filterAndSortEventsList(events);
ListView eventsListView = (ListView) view
.findViewById(R.id.live_match_list);
eventsListView.setAdapter(new LiveEventsAdapter());
return view;
}
什麼可能呢?
什麼是事件片段中的第211行 – stinepike
http://stackoverflow.com/a/9857669/1168654和http://stackoverflow.com/a/6253664/1168654 –
代碼中沒有進入第211行。應用程序粉碎在super.onStart() 你爲什麼問? – roiberg