-1

I am trying to declare a RecyclerView in an activity in my project. When I switch to this activity, the project crashes. I am getting a NullPointerException when I try to instantiate my RecyclerView, see error below:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.marykate.marykatefordefyp, PID: 13490
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.marykate.marykatefordefyp/com.example.marykate.marykatefordefyp.ViewFavourites}: java.lang.NullPointerException
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2264)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2313)
        at android.app.ActivityThread.access$1100(ActivityThread.java:141)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5336)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
        at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.NullPointerException
        at com.example.marykate.marykatefordefyp.ViewFavourites.onCreate(ViewFavourites.java:54)
        at android.app.Activity.performCreate(Activity.java:5302)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1090)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2228

I have looked at similar questions on this site but none have the answer I am looking for. I am not referencing the wrong xml file and I am calling the correct RecyclerView. See my code below:

 RecyclerView eventsListview;
List<Favourite> favourites = new ArrayList<>();
    FaveAdapter adapter = new FaveAdapter(this, R.layout.eventlist_layout, favourites);

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_favourites);

        eventsListview.findViewById(R.id.eventsListview1); //the line causing an error

Does anyone know what might be causing this?

ADM
  • 20,406
  • 11
  • 52
  • 83
minikate
  • 305
  • 1
  • 6
  • 16

1 Answers1

1
eventsListview = (RecyclerView)findViewById(R.id.eventsListview1); 
adnbsr
  • 635
  • 4
  • 13