Note that there are some explanatory texts on larger screens.

plurals
  1. POjava.lang.IllegalStateException: Cannot add header view to list Android
    primarykey
    data
    text
    <p>I have one issues in my application, I am setting header view to <code>listview</code> dynamically but am getting below error, I have two activities , A and B according my condition I am setting header view to <code>listview</code> when I am setting headerview in A activity it works fine but when A activity false my condition and go to B activity there my condition is true then come to A activity i need to add header view there I am getting Error................ I have tried to added onStart(), onResume() methods, but still am getting same error..... how to fix it</p> <p>Java code</p> <pre><code>on Strat() { if (mDrawerList.getHeaderViewsCount()&lt;1) { TextView headerText = new TextView(mContext); headerText.setGravity(Gravity.CENTER); headerText.setTextColor(getResources().getColor(R.color.white_color)); headerText.setPadding(20, 12, 20, 12); headerText.setTextSize(18); headerText.setText(mSessionManager.getUserName()); mDrawerList.addHeaderView(headerText); } adapter = new NavDrawerListAdapter(mContext, navDrawerItems); mDrawerList.setDividerHeight(2); mDrawerList.setAdapter(adapter); adapter.notifyDataSetChanged(); } </code></pre> <p>Error message</p> <pre><code>2-20 15:15:34.799: E/AndroidRuntime(13111): FATAL EXCEPTION: main 12-20 15:15:34.799: E/AndroidRuntime(13111): java.lang.RuntimeException: Unable to resume activity {com.examle.EventListActivity}: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2790) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2819) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.os.Handler.dispatchMessage(Handler.java:99) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.os.Looper.loop(Looper.java:137) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.app.ActivityThread.main(ActivityThread.java:5103) 12-20 15:15:34.799: E/AndroidRuntime(13111): at java.lang.reflect.Method.invokeNative(Native Method) 12-20 15:15:34.799: E/AndroidRuntime(13111): at java.lang.reflect.Method.invoke(Method.java:525) 12-20 15:15:34.799: E/AndroidRuntime(13111): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 12-20 15:15:34.799: E/AndroidRuntime(13111): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12-20 15:15:34.799: E/AndroidRuntime(13111): at dalvik.system.NativeStart.main(Native Method) 12-20 15:15:34.799: E/AndroidRuntime(13111): Caused by: java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called. 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.widget.ListView.addHeaderView(ListView.java:258) 12-20 15:15:34.799: E/AndroidRuntime(13111): at android.widget.ListView.addHeaderView(ListView.java:287) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload