الجمعة، 20 ديسمبر 2013

java.lang.IllegalStateException: Cannot add header view to list Android

i have one issues in my application , am setting header view to listview dynamically but am getting below error, i have two activies , A and B according my codition am setting header view to listview when am setting hederview in A activity it work fine but when A activity false my codition and go to B activity there am my contion is ture then come to A activity i neeed to add header view there am getting Error................ i have tryied to added onStart(), onResume() methods, but still am getting same error..... how to fix it

Java code

if (mDrawerList.getHeaderViewsCount()<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); }

Error message

2-20 15:15:34.799: E/AndroidRuntime(13111): FATAL EXCEPTION: main12-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)

View the original article here

ليست هناك تعليقات:

إرسال تعليق