Android Recycler View - Activity - Error in Recycler View

Asked 2 years ago, Updated 2 years ago, 156 views

If you change the image of Recyclerview B when an event occurs in Recyclerview A, there is an error in this part.

Logic is like this. It's A - Activity - B Recycler View.

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: jerry.apptest.myclair, PID: 18802
                  java.lang.NullPointerException: Attempt to read from field 'android.view.View android.support.v7.widget.RecyclerView$ViewHolder.itemView' on a null object reference
                      at jerry.apptest.myclair.SoundSelectActivity.onClickSound_disable(SoundSelectActivity.java:309)
                      at jerry.apptest.adapter.SoundChannel_Compact_Adapter$ViewHolder.onClick(SoundChannel_Compact_Adapter.java:109)
                      at android.view.View.performClick(View.java:4811)
                      at android.view.View$PerformClick.run(View.java:20136)
                      at android.os.Handler.handleCallback(Handler.java:815)
                      at android.os.Handler.dispatchMessage(Handler.java:104)
                      at android.os.Looper.loop(Looper.java:194)
                      at android.app.ActivityThread.main(ActivityThread.java:5546)
                      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:967)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

SoundSelectActivity.java:309

    @Override
    public void onClickSound_disable(int position) {

        ProgressBar sound_progres;
        sound_progres = (ProgressBar) mRecyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.sound_progress);
        if(mSoundlist.get(position).getismutte()){
            sound_progres.setProgressDrawable(SoundSelectActivity.this.getResources().getDrawable(R.drawable.circularprogress_disable));
            mSoundlist.get(position).setismutte(false);
        }else{
            sound_progres.setProgressDrawable(SoundSelectActivity.this.getResources().getDrawable(R.drawable.circularprogress));
            mSoundlist.get(position).setismutte(true);
        }
    }

SoundChannel_compact_Adapter.java:109

                case R.id.sound_progress_compact:
                    Toast.makeText(context,"this "+position,Toast.LENGTH_SHORT).show();
                    sound_progress_compact.setProgressDrawable(context.getResources().getDrawable(R.drawable.circularprogress_disable));
                    ClickInterface.onClickSound_disable(position);
                    break;

android recyclerview data image interface

2022-09-22 20:32

1 Answers

As you might expect, I guess the itemView part is null I think we should follow the part that generates itemView and try to debug it.

You need to take a log to check if the itemView view has been created.


2022-09-22 20:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.