There is an activity on which a fragment is superimposed. I'm trying to add CardView with RecyclerView, but going out

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hondle.biling/com.example.hondle.biling.activity.MainOnline}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2351) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403) at android.app.ActivityThread.access$600(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5391) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.hondle.biling.fragments.MainOnlineFragment.onCreateView(MainOnlineFragment.java:85) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:955) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1138) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:740) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1501) at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:551) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1232) at android.app.Activity.performStart(Activity.java:5132) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2324) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2403) at android.app.ActivityThread.access$600(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:194) at android.app.ActivityThread.main(ActivityThread.java:5391) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) at dalvik.system.NativeStart.main(Native Method) 

If you do this in the activation itself, then everything works, but not in the fragment. Here is the code on which the program stumbles.

 @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_main_online, container, false); List<ItemObject> rowListItem = getAllItemList(); lLayout = new LinearLayoutManager(getActivity()); RecyclerView rView = (RecyclerView)view.findViewById(R.id.recycler_view); rView.setLayoutManager(lLayout); RecyclerViewAdapter rcAdapter = new RecyclerViewAdapter(getActivity(), rowListItem); rView.setAdapter(rcAdapter); // Inflate the layout for this fragment return view; } private List<ItemObject> getAllItemList(){ List<ItemObject> allItems = new ArrayList<ItemObject>(); allItems.add(new ItemObject("United States", R.drawable.newyork)); allItems.add(new ItemObject("Canada", R.drawable.canada)); allItems.add(new ItemObject("United Kingdom", R.drawable.uk)); allItems.add(new ItemObject("Germany", R.drawable.germany)); allItems.add(new ItemObject("Sweden", R.drawable.sweden)); return allItems; } 
  • You have something null on the 85th line. What is this string? - Yuriy SPb
  • one
    I think on the 84th line (RecyclerView)view.findViewById(R.id.recycler_view) , there’s nothing more to return here. Probably the fragment_main_online layout does not contain the element recycler_view - xkor

1 answer 1

That's right, that was the main problem, thanks.

I think on the 84th line (RecyclerView) view.findViewById (R.id.recycler_view), there’s nothing more to return here. Probably the fragment_lay_online layout does not contain the element recycler_view - xkor 20 hours ago