XML : Android RecyclerView is null

It was working all the time before, but suddently it doesn't, even though i didn't even change the code... I'm getting a null reference on my RecyclerView instance, as the exception tells me... Here is my Java Code:

      RecyclerView recyclerView;      RecyclerView.Adapter rvadapter;      RecyclerView.LayoutManager rvLayoutManager;        static ArrayList<String> itemTexte;        File dir;        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_recycler_view);          dir = new File(Environment.getExternalStorageDirectory(), "Notizen");          if (!dir.exists()) {              try {                  dir.mkdirs();              } catch (Exception e) {                  e.printStackTrace();              }          }            itemTexte = new ArrayList<>();            recyclerView = (RecyclerView) findViewById(R.id.recyclerview);            rvLayoutManager = new LinearLayoutManager(RecyclerViewActivity.this);          recyclerView.setLayoutManager(rvLayoutManager);            rvadapter = new RvAdapterKlasse(RecyclerViewActivity.this);          recyclerView.setAdapter(rvadapter);            notizenSetup();      }    

The error is in recyclerView.setLayoutManager(rvLayoutManager); Here is my XML:

  <?xml version="1.0" encoding="utf-8"?>  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:layout_width="match_parent"      android:layout_height="match_parent"      tools:context="at.wurz.david.recyclerviewtemplate.RecyclerViewActivity">        <android.support.v7.widget.RecyclerView          android:layout_height="match_parent"          android:layout_width="match_parent"          android:id="@+id/recyclerview"      />    </RelativeLayout>    

I searched for the error, but all topics are at least 1 year old and say that google already fixed that error.

No comments:

Post a Comment