DeevithShettys / test

deevith
0 stars 0 forks source link

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setAdapter(androidx.recyclerview.widget.RecyclerView$Adapter)' on a null object reference #1

Open DeevithShettys opened 4 years ago

DeevithShettys commented 4 years ago
                                                           **Error:**

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setAdapter(androidx.recyclerview.widget.RecyclerView$Adapter)' on a null object reference at com.Deevith1.samplestickerapp.StickerPackListActivity.showStickerPackList(StickerPackListActivity.java:60) at com.Deevith1.samplestickerapp.StickerPackListActivity.onCreate(StickerPackListActivity.java:39) at android.app.Activity.performCreate(Activity.java:7136) at android.app.Activity.performCreate(Activity.java:7127) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2905) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3060)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1818)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loop(Looper.java:193)  at android.app.ActivityThread.main(ActivityThread.java:6762)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

                                      **Java code**

private void showStickerPackList(List stickerPackList) { allStickerPacksListAdapter = new StickerPackListAdapter(stickerPackList, onAddButtonClickedListener); packRecyclerView.setAdapter(allStickerPacksListAdapter); packLayoutManager = new LinearLayoutManager((this)); packLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration( packRecyclerView.getContext(), packLayoutManager.getOrientation() ); packRecyclerView.addItemDecoration(dividerItemDecoration); packRecyclerView.setLayoutManager(packLayoutManager); packRecyclerView.getViewTreeObserver().addOnGlobalLayoutListener(this::recalculateColumnCount); }

                                   **XML code**

<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout 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=".StickerPackListActivity" tools:showIn="@layout/activity_sticker_pack_list">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:textColor="@android:color/holo_red_dark"
    android:id="@+id/error_message"
    tools:ignore="MissingConstraints" />

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/sticker_pack_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:ignore="MissingConstraints"
    />

</androidx.constraintlayout.widget.ConstraintLayout>

DeevithShettys commented 4 years ago

please help me to fix this issue