cymcsg / UltimateRecyclerView

A RecyclerView(advanced and flexible version of ListView in Android) with refreshing,loading more,animation and many other features.
Apache License 2.0
7.22k stars 1.43k forks source link

IllegalStateException: ViewStub must have a non-null ViewGroup viewParent #183

Open meness opened 9 years ago

meness commented 9 years ago

Hi,

I think you're setting something null and because of that, Android throws an exception.

The complete trace is:

java.lang.IllegalStateException: ViewStub must have a non-null ViewGroup viewParent
            at android.view.ViewStub.inflate(ViewStub.java:292)
            at com.marshalchen.ultimaterecyclerview.UltimateRecyclerView.setEmptyView(UltimateRecyclerView.java:183)
            at com.collect_up.c_up.fragments.ShopPagerFragment$2.onFailure(ShopPagerFragment.java:145)
            at com.collect_up.c_up.helpers.Pagination$5.onFailure(Pagination.java:123)
            at com.loopj.android.http.AsyncHttpResponseHandler.handleMessage(AsyncHttpResponseHandler.java:379)
            at com.loopj.android.http.AsyncHttpResponseHandler$ResponderHandler.handleMessage(AsyncHttpResponseHandler.java:195)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

The error was thrown because of following line that I've set.

mRecyclerView.setEmptyView(R.layout.empty_list_view_cause_get_data_error);

And the used layout content is:

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="@string/coudnt_load_data" />
yudhir commented 9 years ago

ViewStub is null. I encountered the same when I tried setting a different Loading and LoadFailed Views. Once you set the empty view , you cannot set another view again because The stub is already inflated.

meness commented 8 years ago

So this is a bug and should be fixed! because I must be able to set the layout dynamically. Thanks.

firaskafri commented 8 years ago

Any updates with this?

meness commented 8 years ago

@firasalkafri Not yet :( @cymcsg Sir we're waiting for a big update. I'm using this library inside my very huge project and I really want to see regular updates. Thanks.

cymcsg commented 8 years ago

@alirezaaa It's very kind of you. As I am really too busy these days I can hardly find enough time to improve the library regularly . I'll try to fix bugs and enhance the library.

lulee007 commented 8 years ago

@alirezaaa try use UltimateRecyclerView.getEmptyView() and remove its children view, then inflate and add your custom view into its parent view

View view=ultimateRecyclerView.getEmptyView();
if(view!=null){
     ViewGroup viewGroup= ((ViewGroup) view.getParent());
     viewGroup.removeView(view);
viewGroup.addView(LayoutInflater.from(viewGroup.getContext()).inflate(errorViewRsid,null));
}else{
ultimateRecyclerView.setEmptyView();
}