1

I'm building a chat app where i added a feature of storyview , now i want to show the list of view on story over the bottomsheetdialog , for that i used FirebaseRecyclerAdapter to show the list over bottomsheet but when i click to open the bottomsheet the app crashes with error : Binary XML file line #3 in com.example.hichat:layout/views_item: Binary XML file line #3 in com.example.hichat:layout/views_item: Error inflating class <unknown> Caused by: android.view.InflateException: Binary XML file line #3 in com.example.hichat:layout/views_item: Error inflating class <unknown>

here is my code to create the bottomsheet:

r_seen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                storiesProgressView.pause();
                BottomSheetDialog sheetDialog = new BottomSheetDialog(StoryActivity.this,R.style.BottomSheetDialogTheme);
                View sheetView = LayoutInflater.from(getApplicationContext())
                        .inflate(R.layout.views_bottom_dialog,(LinearLayout)findViewById(R.id.dialog_container));
                sheetView.findViewById(R.id.views_cancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        sheetDialog.dismiss();
                        storiesProgressView.resume();
                    }
                });
                viewrecyclerView = sheetView.findViewById(R.id.views_recyclerlist);
                viewrecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
                sheetDialog.setContentView(sheetView);
                sheetDialog.show();
                loadViewList(storyids.get(counter));
            }
        });

here is my code to load the list of views:

 private void loadViewList(String storyid) {

        viewRef = FirebaseDatabase.getInstance().getReference("story").child(userid)
                .child(storyid).child("views");

        FirebaseRecyclerOptions options =
                new FirebaseRecyclerOptions.Builder<User>()
                        .setQuery(viewRef,User.class)
                        .build();

        FirebaseRecyclerAdapter<User,ViewsViewHolder> adapter = new FirebaseRecyclerAdapter<User, ViewsViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull ViewsViewHolder holder, int position, @NonNull User model) {

                String userIDs = getRef(position).getKey();

                FirebaseDatabase.getInstance().getReference("users")
                        .child(userIDs).addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        User user = snapshot.getValue(User.class);
                        Glide.with(getApplicationContext())
                                .load(user.getProfileImage())
                                .placeholder(R.drawable.avatar)
                                .into(holder.viewProfileImage);
                        holder.viewUserName.setText(user.getName());
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {

                    }
                });


            }

            @NonNull
            @Override
            public ViewsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.views_item,parent,false);
                return new ViewsViewHolder(view);
            }
        };

        viewrecyclerView.setAdapter(adapter);
        adapter.startListening();
    }

full stack trace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hichat, PID: 4987
    android.view.InflateException: Binary XML file line #3 in com.example.hichat:layout/views_item: Binary XML file line #3 in com.example.hichat:layout/views_item: Error inflating class <unknown>
    Caused by: android.view.InflateException: Binary XML file line #3 in com.example.hichat:layout/views_item: Error inflating class <unknown>
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:852)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1008)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:657)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
        at com.example.hichat.Activity.StoryActivity$6.onCreateViewHolder(StoryActivity.java:215)
        at com.example.hichat.Activity.StoryActivity$6.onCreateViewHolder(StoryActivity.java:185)
        at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:7295)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6416)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
        at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3686)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:833)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:145)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25969)
E/AndroidRuntime:     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:842)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:721)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:7112)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:834)
        at android.view.View.measure(View.java:25969)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:3905)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:2620)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2887)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2340)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9057)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1040)
        at android.view.Choreographer.doCallbacks(Choreographer.java:864)
        at android.view.Choreographer.doFrame(Choreographer.java:791)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1025)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:255)
        at android.app.ActivityThread.main(ActivityThread.java:8212)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
     Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 13: TypedValue{t=0x2/d=0x7f040373 a=-1}
        at android.content.res.TypedArray.getDrawableForDensity(TypedArray.java:997)
        at android.content.res.TypedArray.getDrawable(TypedArray.java:981)
        at android.view.View.<init>(View.java:5626)
        at android.view.ViewGroup.<init>(ViewGroup.java:700)
        at android.view.ViewGroup.<init>(ViewGroup.java:696)
        at android.view.ViewGroup.<init>(ViewGroup.java:692)
        at androidx.constraintlayout.widget.ConstraintLayout.<init>(ConstraintLayout.java:587)
            ... 76 more
Amit Swami
  • 23
  • 4
  • So it's an issue more related to your layout file rather than Firebase, right? – Alex Mamo Mar 29 '22 at 05:56
  • 1
    Post the full stack trace. In an inflation error, its always the bottom most exception that's the real problem, and there's always at least 2, if not 3 or 4 of them. – Gabe Sechan Mar 29 '22 at 05:57
  • @AlexMamo No, it likely isn't a problem with the layout. Generally when you see this it's a crash while initializing the views, but since it happens while inflating an xml file that's the top crash you see, and the real crash is wrapped underneath it. It could be an xml problem, but most of the time it ends up being a null pointer or a miscast or something of the sort. – Gabe Sechan Mar 29 '22 at 05:59
  • @Gabe Sechan yes, when i initialize the recyclerview out of the bottomsheet , then it didnot crash but also the item of recyclerview not shown – Amit Swami Mar 29 '22 at 06:02
  • @AmitSwami That's great. But post the full stacktrace. We're not going to guess what the problem is when that will tell us exactly what and where the problem is. – Gabe Sechan Mar 29 '22 at 06:03
  • @GabeSechan i have posted , it pointing the error over oncreateviewholder method – Amit Swami Mar 29 '22 at 06:07
  • should i posted something more? – Amit Swami Mar 29 '22 at 06:21
  • Check this: https://stackoverflow.com/a/47010386/7493938 – Mario Huizinga Mar 29 '22 at 08:23
  • @MarioHuizinga thankyou so much , very accurate and simple solution for the problem, but why getApplicationContext not working in inflating the bottomsheet? – Amit Swami Mar 29 '22 at 08:49
  • Because the application context isn't supposed to have views attached to it. Views belong to an Activity, they need to be created with that Activity's context. The resource system and styling system depend on that. – Gabe Sechan Mar 29 '22 at 14:12

0 Answers0