I am new on Android. Yesterday I added RecyclerView and CardView to my project on BlankFragment. It is running without error but when I open it gives "program has been stopped". In tutorial they include RecyclerView into LinearLayout. But in my BlankFragment I have already FragmentLayout, that's why I think I don't need it. Other guys adviced to look at Logcat on androidStudio, after did it I get AndroidRuntime: FATALEXCEPTION: main
Process: com.example.ganz.afex_with_default_navigation, PID: 10058
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ganz.afex_with_default_navigation/com.example.ganz.afex_with_default_navigation.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
at com.example.ganz.afex_with_default_navigation.MainActivity.onCreate(MainActivity.java:46)
at android.app.Activity.performCreate(Activity.java:7174)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
On this Logcat I was linked to my MainActivity.java:46. The 46th row stays in the OnCreate method:
lstTovar = new ArrayList<>();
lstTovar.add(new Tovar_tavsiya("Modadagi kiyimlar", "Tovar kategoriyasi", "Description", R.drawable.tile_bg_1));
lstTovar.add(new Tovar_tavsiya("Chet eldan uskunalar", "Tovar kategoriyasi", "Description", R.drawable.tile_bg_2));
lstTovar.add(new Tovar_tavsiya("Tekstil mahsulotlari", "Tovar kategoriyasi", "Description", R.drawable.tile_bg_3));
RecyclerView myrv = (RecyclerView) findViewById(R.id.recyclerview_id);
Recyclerview_Adapter myrv_Adapter = new Recyclerview_Adapter(this, lstTovar);
myrv.setLayoutManager(new GridLayoutManager(this, 3)); ===IT IS THE 46TH ROW===
myrv.setAdapter(myrv_Adapter);
Here fragment_blank.xml:
<FrameLayout 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="com.example.ganz.afex_with_default_navigation.BlankFragment">
<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
</FrameLayout>
P.S: I have also adapters, activities, java files for them. If I will add them here too I guess the question will be messed. If you need their parts to solve the problem I will share them. Thank you in advance!