Closed marcorighini closed 10 years ago
Hello, I have an app with SlideExpandableListView (without fragments) and I also have a similar error.
java.lang.RuntimeException: Unable to start activity ComponentInfo{...XXActivity}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836) at android.app.ActivityThread.access$1600(ActivityThread.java:117) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:130) at android.app.ActivityThread.main(ActivityThread.java:3687) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.tjerkw.slideexpandable.library.SlideExpandableListView.onRestoreInstanceState(SlideExpandableListView.java:81) at com.tjerkw.slideexpandable.library.ActionSlideExpandableListView.onRestoreInstanceState(ActionSlideExpandableListView.java:1) at android.view.View.dispatchRestoreInstanceState(View.java:6278) at android.view.ViewGroup.dispatchThawSelfOnly(ViewGroup.java:1228) at android.widget.AdapterView.dispatchRestoreInstanceState(AdapterView.java:767) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.ViewGroup.dispatchRestoreInstanceState(ViewGroup.java:1215) at android.view.View.restoreHierarchyState(View.java:6257) at com.android.internal.policy.impl.PhoneWindow.restoreHierarchyState(PhoneWindow.java:1564) at android.app.Activity.onRestoreInstanceState(Activity.java:844) at android.app.Activity.performRestoreInstanceState(Activity.java:816) at android.app.Instrumentation.callActivityOnRestoreInstanceState(Instrumentation.java:1096) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1629) ... 12 more
Ditto:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.MAW.yourclubfree/org.MAW.yourclubfree.Activity_Base}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2081) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2106) at android.app.ActivityThread.access$700(ActivityThread.java:134) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1217) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4856) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.writeBitSet(AbstractSlideExpandableListAdapter.java:269) at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter.access$400(AbstractSlideExpandableListAdapter.java:22) at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter$SavedState.(AbstractSlideExpandableListAdapter.java:290) at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter$SavedState.(AbstractSlideExpandableListAdapter.java:279) at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter$SavedState$1.createFromParcel(AbstractSlideExpandableListAdapter.java:304) at com.tjerkw.slideexpandable.library.AbstractSlideExpandableListAdapter$SavedState$1.createFromParcel(AbstractSlideExpandableListAdapter.java:302) at android.os.Parcel.readParcelable(Parcel.java:2103) at android.os.Parcel.readValue(Parcel.java:1965) at android.os.Parcel.readSparseArrayInternal(Parcel.java:2255) at android.os.Parcel.readSparseArray(Parcel.java:1687) at android.os.Parcel.readValue(Parcel.java:2022) at android.os.Parcel.readMapInternal(Parcel.java:2226) at android.os.Bundle.unparcel(Bundle.java:223) at android.os.Bundle.getSparseParcelableArray(Bundle.java:1232) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:845) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070) at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1856) at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:210) at org.MAW.yourclubfree.Activity_Base.onCreate(Activity_Base.java:40) at android.app.Activity.performCreate(Activity.java:5047) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2045) ... 11 more
Hi,
I got a null pointer exception at the same line (298 in AbstractSlideExpandableListAdapter.writeBitSet) and in the same situations. Has anyone solved this problem?
Thanks!
At the moment this bug has not been fixed. I hope it will be soon.
There are two separate issues reported here. Both throw an NullPointerException. But the cause is different. One ise caused by using v4 support library. It has an easy fix.
The other issue reported by @CandidoCaballero is caused by the fact no adapter was set on the ListView. Is this true @CandidoCaballero
What's the easy fix for the first problem, the one related to v4 support library?
Hello,
I´m not sure if I´m doing something wrong,
this is the call ActionSlideExpandableListView ExpandableListView; ExpandableListView = (ActionSlideExpandableListView) findViewById(R.id.paired_devices); MyCustomAdapter mPairedDevicesArrayAdapterNew = new MyCustomAdapter( context, R.layout.expandable_list_item, mItems, activity); ExpandableListView.setAdapter(mPairedDevicesArrayAdapterNew);
This is the adapter
public class MyCustomAdapter extends ArrayAdapter
Activity activity;
String log="MyCustomAdapter";
public MyCustomAdapter(Context context, int textViewResourceId, String[] objects, Activity activity) { super(context, textViewResourceId, objects); this.activity=activity; }
@Override
public View getView(int position, View convertView, ViewGroup parent) {
try {
// Inflate the layout, mainlvitem.xml, in each row.
LayoutInflater inflater = activity.getLayoutInflater();
View row = inflater.inflate(R.layout.expandable_list_item, parent,
false);
// Declare and define the TextView, "item." This is where
// the name of each item will appear.
TextView item = (TextView) row.findViewById(R.id.title);
item.setText(ListDevicesBTActivity.mItems[position]);
TextView desc = (TextView) row.findViewById(R.id.desc);
desc.setText(ListDevicesBTActivity.mDescs[position]);
// Declare and define the TextView, "icon." This is where the icon
// in each row will appear.
ImageView icon = (ImageView) row.findViewById(R.id.icon);
icon.setBackgroundDrawable(ListDevicesBTActivity.mIcons[position]);
ImageView icon2 = (ImageView) row.findViewById(R.id.icon2);
icon2.setBackgroundDrawable(ListDevicesBTActivity.mIcons2[position]);
ImageView sound = (ImageView) row.findViewById(R.id.sound);
if (ListDevicesBTActivity.mSound[position] != null
&& ListDevicesBTActivity.mSound[position] == true)
sound.setVisibility(ImageView.VISIBLE);
else {
sound.setVisibility(ImageView.GONE);
}
ImageView deviceIcon = (ImageView) row.findViewById(R.id.device);
deviceIcon.setBackgroundResource(R.drawable.bluetooth);
return row;
} catch (Exception e) {
String err = (e.getMessage() == null) ? "error"
: e.getMessage();
Log.e(log, err);
return null;
}
}
}
@CandidoCaballero a couple things I notice, please don't call the instance of the ActionSlideExpandableListView ExpandableListView
, it gets extremely confusing as there is a core API view called ExpandableListView
.
Anyways you are improperly setting the adapter. You have to use the
Edit: My mistake it just wraps it for you, never looked at the implementation of SlideExpandableListAdapter
to wrap your adapter or it will throw an NPE.ActionSlideExpandableListView
Hello JesseFarebro, I Implemented the adapter as you say but the problem is still there.
Any other idea about what is the problem? Thank you very much for your help.
@tjerkw no news for fixing the first problem?
@marcorighini when you have a fix for the problem please submit a patch, i'm happy to accept it.
This is an open source project so I gladly accept fixes.
Currently I dont have the time to work on these issues. Thats why i opened this project to a lot more contributers.
@tjerkw Sorry, i've understood that the fix was really easy so I asked you :)
If I'll fix it, I'll release the patch.
@marcorighini I'm dealing with this currently. Did you resolve it in your project?
Hey. I am also facing ths problem. Can anybody give me a hint how to fix this? Thanks.
I am also facing this issue, any leads on fixing this please?
We just used the blog post that inspired the library to write our own custom solution rather than spend more time trying to debug this. http://udinic.wordpress.com/2011/09/03/expanding-listview-items/
A dirty fix for this problem is to do a check to see if the list adapter is empty. If it is create a test list item and populate the list with it, then set the list visibility to gone.
a possible solution is to simply initialize openItems in SavedState with an instance of BitSet instead of null : In SavedState (in AbstractSlideExoandableListAdapter#310) : public BitSet openItems = new BitSet();
@chemouna, We have tried that. But in that case, a different exception occurs. It still crashes, but in a different function.
Caused by: java.lang.RuntimeException: Parcel android.os.Parcel@428f0640: Unmarshalling unknown type code 7209057 at offset 604
at android.os.Parcel.readValue(Parcel.java:2038)
at android.os.Parcel.readMapInternal(Parcel.java:2254)
at android.os.Bundle.unparcel(Bundle.java:223)
at android.os.Bundle.getSparseParcelableArray(Bundle.java:1237)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:861)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
at android.support.v4.app.FragmentManagerImpl.dispatchCreate(FragmentManager.java:1872)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:215)
at com.zoylab.keepintouch.ContactManager.onCreate(ContactManager.java:58)
at android.app.Activity.performCreate(Activity.java:5369)
@satyadeepk you're right , i dont know if this is the same problem as yours but somehow in my SavedState implementations of SavedState(Parcel in) and writeToParcel(Parcel out, int flags) was somehow reversed, instead it should be :
private SavedState(Parcel in) {
super(in);
lastOpenPosition = in.readInt();
openItems = readBitSet(in);
}
@Override
public void writeToParcel(Parcel out, int flags) {
super.writeToParcel(out, flags);
out.writeInt(lastOpenPosition);
writeBitSet(out, openItems);
}
@chemouna, Did you try with reversing the SavedState(Parcel in) and writeToParcel(Parcel out, int flags) as you mentioned above?
Hi,
I had the same issue. I was using Nested Fragments inside a ViewPager. I simply used 2 things and the issue was fixed. 1) extended my PagerAdapter by FragmentStatePagerAdapter instead of just FragmentPagerAdapter 2) and in my parent fragment I just added this mViewPager.setOffscreenPageLimit(4); //4 is the number of nested fragments.
FYI my app architecture is NavigationDrawer Fragent [ViewPager] Fragment_A [SlideExpandableListView] Fragment_B [SlideExpandableListView] Fragment_C [SlideExpandableListView] Fragment_D [SlideExpandableListView]
Hope it helps someone...
how to fix this error ? who can tell me please
I commited some code which should prevent the crash. I'm not sure why we got a nullpointerexception but at least it should be prevented now. I probably didnt resolve the root issue.. But can anybody confirm wether its is working.
It seems to work on mine now, Thanks!
how to fix this bug?
@hamzaawwad its already fixed. If not please try fixing it yourself and provide a pull request.
yes its fixed I updated the library thanks alot
Hi, sometimes I got a null pointer exception at line 298 in AbstractSlideExpandableListAdapter.writeBitSet, immediately after rotating or waking up from sleep mode.
Here is the stacktrace: