I have 2 Recyclerviews. Both are in the same fragment but the second is in a custom View. I am trying to populate and update the second Recyclerview when a button on the first is clicked with contents of the first Recyclerview.My app crashes when i try to do that. What I have looks like this(summarized for sake of brevity) :
My Adapter's Interface and button click method:
public class MenuListAdapter extends RecyclerView.Adapter<MenuListAdapter.menuListViewHolder> {
//button to be clicked on 1st recyclerview
vholder.btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mOnItemClickLister.getSelectedItemCountById(mItems.get(position));
}
//interface implemented in fragment
public interface Anims{
void getSelectedItemCountById(MenuItem mItem);
}
}
My Fragment:
public class MenuListFragment extends Fragment implements MenuListAdapter.Anims {
//create custom View using with flipboard:bottomsheet
public View createBottomSheetView(){
View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_bottom_sheet,(ViewGroup) getActivity().getWindow().getDecorView(),false);
btmRecyclerView = (RecyclerView) view.findViewById(R.id.bottom_recycler_view);
TextView clear = (TextView) view.findViewById(R.id.clear);
return view;
}
//populate recyclerView in createBottomSheetView() with selected item
@Override
public void getSelectedItemCountById(MenuItem mItem){
bottomSheet = createBottomSheetView();
int size = menuItems.size();
for(int i=0;i<size;i++) {
mItem = menuItems.get(i);
cartItems.add(mItem);
MenuListAdapter btmListAdapter = new MenuListAdapter(cartItems);
btmRecyclerView.setAdapter(menuListAdapter);
btmListAdapter.notifyDataSetChanged();
}
}
The Crash Log:
Process: com.example.wggi, PID: 30300
java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference
at com.example.wggi.Fragments.MenuListFragment.getSelectedItemCountById(MenuListFragment.java:323)
at com.example.wggi.Adapters.MenuListAdapter$1.onClick(MenuListAdapter.java:154)
at android.view.View.performClick(View.java:5207)
at android.view.View$PerformClick.run(View.java:21177)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5442)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:738)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:628)
09-16 20:20:31.090 1274-2771/? W/ActivityManager: Force finishing activity com.example.wggi/.RestaurantDetails
java.lang.ExceptionInInitializerError
at com.backendless.Invoker.invokeSync(Invoker.java:95)
at com.backendless.Invoker$1.run(Invoker.java:71)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String android.content.SharedPreferences.getString(java.lang.String, java.lang.String)' on a null object reference
at com.backendless.AndroidBackendlessPrefs.restoreAuthKeysFromPreferences(AndroidBackendlessPrefs.java:98)
at com.backendless.AndroidBackendlessPrefs.getAuthKeys(AndroidBackendlessPrefs.java:91)
at com.backendless.AndroidBackendlessPrefs.getApplicationId(AndroidBackendlessPrefs.java:51)
at com.backendless.Backendless.getApplicationId(Backendless.java:191)
at com.backendless.AndroidHeadersManager.<init>(AndroidHeadersManager.java:34)
at com.backendless.AndroidHeadersManager.getInstance(AndroidHeadersManager.java:22)
at com.backendless.HeadersManager.<clinit>(HeadersManager.java:28)
at com.backendless.Invoker.invokeSync(Invoker.java:95)
at com.backendless.Invoker$1.run(Invoker.java:71)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)