Error with notifyItemInserted () when sending an Android Studio message: Error inflating class android.support.v4.widget.CircleImageView

1

I am making a simple chat app, when I write a message and show it on the screen the app stops, I suspect that the error is in notifyItemInserted () and I would like to know if I am misusing the function or if it exists another way to make messages appear on the screen.

Thanks for your help!

public class AdapterMensajes extends RecyclerView.Adapter<HolderMensaje> {

        private List<Mensaje> listMensaje = new ArrayList<>();
        private Context c;

        public AdapterMensajes(Context c) {
            this.c = c;
        }

        public void addMensaje(Mensaje m){
            listMensaje.add(m);
            notifyItemInserted(listMensaje.size());
        }

This is the error shown in the LogCat:

  

09-06 15: 27: 39.896 6174-6174 / vdachi.startalking E / AndroidRuntime:   FATAL EXCEPTION: main       Process: vdachi.startalking, PID: 6174       android.view.InflateException: Binary XML file line # 16: Binary XML file line # 16: Error inflating class   android.support.v4.widget.CircleImageView       Caused by: android.view.InflateException: Binary XML file line # 16: Error inflating class android.support.v4.widget.CircleImageView       Caused by: java.lang.NoSuchMethodException: [class android.content.Context, interface android.util.AttributeSet]

    
asked by VDachi 06.09.2018 в 17:12
source

1 answer

0

The problem is that you are trying to inflate a class that does not exist in the SDK ... well in this case it exists but it can NOT be instantiated:

 <android.support.v4.widget.CircleImageView
                android:id="@+id/picture"
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/ic_androide" />

I suggest using another option like link ,

example:

      <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/CircleImageView"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_gravity="center_vertical"
            android:src="@drawable/androide" />

adding the dependency within your /app/build.gradle :

dependencies {
  ...
  implementation 'de.hdodenhof:circleimageview:2.2.0'
  ...
}

Review other options:

link

    
answered by 06.09.2018 / 17:46
source