Skip to content

Commit

Permalink
Fix "Unable to start activity ComponentInfo" error
Browse files Browse the repository at this point in the history
04-02 15:04:28.194  14490-14490/com.example.androidforios.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidforios.app/com.example.androidforios.app.activities.TripDetailActivity}: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.
            at android.widget.ListView.addHeaderView(ListView.java:258)
            at android.widget.ListView.addHeaderView(ListView.java:287)
            at com.example.androidforios.app.fragments.TripDetailFragment.onViewCreated(TripDetailFragment.java:73)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:941)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
            at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:570)
            at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
            at android.app.Activity.performStart(Activity.java:5143)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
  • Loading branch information
hffmnn committed Apr 2, 2014
1 parent 4652a7c commit a497a45
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ public void onCreate(Bundle savedInstanceState) {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Prediction[] predictions= mTrip.predictions.toArray(new Prediction[mTrip.predictions.size()]);
PredictionArrayAdapter predictionArrayAdapter = new PredictionArrayAdapter(getActivity().getApplicationContext(), predictions);
setListAdapter(predictionArrayAdapter);
return super.onCreateView(inflater,container, savedInstanceState);
}
public void onActivityCreated (Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TripDetailsView headerView = new TripDetailsView(getActivity());
headerView.updateFromTripObject(mTrip);
getListView().addHeaderView(headerView);

Prediction[] predictions= mTrip.predictions.toArray(new Prediction[mTrip.predictions.size()]);
PredictionArrayAdapter predictionArrayAdapter = new PredictionArrayAdapter(getActivity().getApplicationContext(), predictions);
setListAdapter(predictionArrayAdapter);
}
}

0 comments on commit a497a45

Please sign in to comment.