So a bit of a heads up, I build a small Mobile Chat App for my task, everything works fine until I get NullPointerException when I do transition from my Contact List menu to the Chat menu... In the error I got this
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.bruh.chatapp, PID: 3797 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bruh.chatapp/com.bruh.chatapp.Obrol}: java.lang.NullPointerException at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2193) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5019) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.bruh.chatapp.Obrol.onCreate(Obrol.java:60) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2243) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5019) 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:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method)
As you can see it's caused by a line in Obrol.java at line 60 which is containing
final DatabaseReference reference1 = firebaseDatabase.getReference("https://databaselink/Message/" + Pesan.Nama+"_"+Pesan.chatWith);
I also have tried change getReference() to getReferencefromUrl() but it stills returns NullPointerException
Then I tried to just make it as a comment to test if the reference1 object did causes this error, and it is, when I relaunch my app, and do transition from my Contact List menu to the Chat menu, it doesn't crash the app and also doesn't return NullPointerException error...
So I wonder why is this happening and how do I solve this error? Oh, here's my Firebase Database structure for additional reference