MyViewHolder with error

0

I'm studying about RecyclerView but when I try to run the code it's a strange error.

android.view.InflateException: Binary XML file line #43: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:761)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
  at br.com.danilo.concurso.adapter.ConcursoAdapter.onCreateViewHolder(ConcursoAdapter.java:32)
 at br.com.danilo.concurso.adapter.ConcursoAdapter.onCreateViewHolder(ConcursoAdapter.java:19)

I searched google, but only found generic answers. If you need to see any files let me know

ps: I'm implementing the RecyclerView in a fragment and its data is coming from a separate class that returns a List<Concurso>

ContestAdapter.java

package br.com.danilo.concurso.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import br.com.danilo.concurso.R;
import br.com.danilo.concurso.model.Concurso;
/**
  * Created by danil on 21/04/2017.
*/
public class ConcursoAdapter  extends RecyclerView.Adapter<ConcursoAdapter.MyViewHolder>{
private List<Concurso> mList;
private LayoutInflater mLayoutInflater;

public ConcursoAdapter(Context context, List<Concurso> concursos){
    mList = concursos;
    mLayoutInflater = (LayoutInflater)  context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
//CHAMANDO SÒ QUANDO SE TEM A NECESSIDADE DE CRIAR UMA NOVA VIEW
// estado de DURTIN
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    //CONSTRUCAO PESADA
    View view = mLayoutInflater.inflate(R.layout.item_list, parent, false);
    MyViewHolder myViewHolder = new MyViewHolder(view);
    return myViewHolder;
}
//CHAMADO TODA HORA
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    holder.titulo.setText(mList.get(position).getNome());
    holder.subtitulo.setText(mList.get(position).getSituacao());


}

@Override
public int getItemCount() {
    return mList.size();
}

public void addListItem(Concurso concurso, int position){
    mList.add(concurso);
    notifyItemInserted(position);

}
//CONSTRUCAO PESADA
public class MyViewHolder extends RecyclerView.ViewHolder{
    public TextView titulo;
    public TextView subtitulo;
    public MyViewHolder(View itemView) {
        super(itemView);

        titulo = (TextView) itemView.findViewById(R.id.text_titulo);
        subtitulo = (TextView) itemView.findViewById(R.id.text_subtitulo);
    }
}
}

item_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="20dp"
    android:paddingLeft="16dp">

<ImageView
    android:layout_alignParentLeft="true"
    android:id="@+id/image"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginRight="6dp"
    android:src="@drawable/ic_dashboard_black_24dp"/>
<TextView
    android:textColor="@color/colorPrimary"
    android:id="@+id/text_titulo"
    android:layout_toRightOf="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="16dp"
    android:text="Concurso IRPF 2017"
    android:textSize="16sp"/>

<TextView
    android:textColor="@color/colorPrimary"
    android:layout_below="@+id/text_titulo"
    android:layout_alignLeft="@+id/text_titulo"
    android:id="@+id/text_subtitulo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingRight="16dp"
    android:text="40 vagas"
    android:textSize="12sp"/>
<ImageView
    android:id="@+id/situacao"
    android:layout_width="50dp"
    android:layout_height="12sp"
    android:src="@drawable/ic_notifications_black_24dp"
    android:layout_below="@+id/text_titulo"
    android:layout_toEndOf="@+id/text_subtitulo"
    android:layout_above="@+id/view_divisor" />
<view
    android:id="@+id/view_divisor"
    android:layout_marginTop="20dp"
    android:layout_alignLeft="@+id/image"
    android:layout_below="@+id/text_subtitulo"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="0.8dp" />

What I had to change in Layout for it to work

...<View
    android:id="@+id/view_divisor"
    android:layout_marginTop="2dp"
    android:layout_alignLeft="@+id/image"
    android:layout_below="@+id/image"
    android:background="@color/colorPrimary"
    android:layout_width="match_parent"
    android:layout_height="0.8dp" />...
    
asked by anonymous 22.04.2017 / 03:10

1 answer

1

The error is nothing strange. Alias, it's very enlightening.

It says that at line 43 of the layout, when trying to compare a null value, it encounters an error. Therefore, it points to the location and describes the problem.

The question is, what appears to be a separator at the end of the layout.

Looking at your code, I have only doubts about the line:

 android:layout_height="0.8dp" 

I do not know if it's possible to use less than 1dp

My suggestion: delete this view and let it work. When in order, place a tab if you still need it.

In this case, use DividerItemDecoration See documentation

ISSUE: As the AP even realized (and I did not), the whole point was that view starts with capital and the code is miniscule.

<view <-- ERRADO

<View <-- CORRETO
    
22.04.2017 / 18:35