2017-10-24 5 views
1

Hallo allerseits bitte helfen Sie mir mit, ich habe Nullpointer bekommt, wenn ich versuche, Daten auf Firebase holen und hier ist meine Datenbank: FIREBASE DATABASENullpointer wenn ich getValue() in Firebase

Und dies ist mein Code:

Also habe ich versucht, die Modellklasse (ResepNusantara) zu den gleichen Datentypen wie meine Datenbank zu erstellen. Aber ich habe immer noch diesen Fehler. Warum das passieren? Vermisse ich etwas?

Das ist mein LogCat:

10-24 22:51:53.422 15766-15766/? I/zygote: Not late-enabling -Xcheck:jni 
(already on) 
10-24 22:51:53.441 15766-15766/? W/zygote: Unexpected CPU variant for X86 using defaults: x86 
10-24 22:51:53.671 15766-15766/com.example.android.frep D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. 
10-24 22:51:53.694 15766-15766/com.example.android.frep D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization. 
10-24 22:51:53.733 15766-15766/com.example.android.frep I/FA: App measurement is starting up, version: 10084 
10-24 22:51:53.733 15766-15766/com.example.android.frep I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE 
10-24 22:51:53.733 15766-15766/com.example.android.frep D/FA: Debug-level message logging enabled 
10-24 22:51:53.734 15766-15766/com.example.android.frep D/FA: AppMeasurement singleton hash: 108831703 
10-24 22:51:53.758 15766-15766/com.example.android.frep V/FA: Collection enabled 
10-24 22:51:53.758 15766-15766/com.example.android.frep V/FA: App package, google app id: com.example.android.frep, 1:199887442989:android:188e4894cfe4b490 
10-24 22:51:53.758 15766-15766/com.example.android.frep I/FA: To enable faster debug mode event logging run: 
                   adb shell setprop debug.firebase.analytics.app com.example.android.frep 
10-24 22:51:53.790 15766-15766/com.example.android.frep V/FA: Registered activity lifecycle callback 
10-24 22:51:53.791 15766-15766/com.example.android.frep I/FirebaseInitProvider: FirebaseApp initialization successful 
10-24 22:51:53.792 15766-15766/com.example.android.frep I/InstantRun: starting instant run server: is main process 
10-24 22:51:53.800 15766-15808/com.example.android.frep V/FA: Using measurement service 
10-24 22:51:53.804 15766-15808/com.example.android.frep V/FA: Connecting to remote service 
10-24 22:51:53.846 15766-15766/com.example.android.frep V/FA: onActivityCreated 
10-24 22:51:53.991 15766-15766/com.example.android.frep I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6 
10-24 22:51:53.991 15766-15766/com.example.android.frep I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6 
10-24 22:51:53.993 15766-15766/com.example.android.frep W/zygote: Skipping duplicate class check due to unrecognized classloader 
10-24 22:51:54.010 15766-15766/com.example.android.frep W/zygote: Skipping duplicate class check due to unrecognized classloader 
10-24 22:51:54.045 15766-15808/com.example.android.frep V/FA: Using measurement service 
10-24 22:51:54.045 15766-15808/com.example.android.frep V/FA: Connection attempt already in progress 
10-24 22:51:54.049 15766-15808/com.example.android.frep V/FA: Activity resumed, time: 2406504 
10-24 22:51:54.071 15766-15816/com.example.android.frep D/OpenGLRenderer: HWUI GL Pipeline 
10-24 22:51:54.075 15766-15819/com.example.android.frep D/NetworkSecurityConfig: No Network Security Config specified, using platform default 
10-24 22:51:54.139 15766-15816/com.example.android.frep I/OpenGLRenderer: Initialized EGL, version 1.4 
10-24 22:51:54.139 15766-15816/com.example.android.frep D/OpenGLRenderer: Swap behavior 1 
10-24 22:51:54.139 15766-15816/com.example.android.frep W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 
10-24 22:51:54.139 15766-15816/com.example.android.frep D/OpenGLRenderer: Swap behavior 0 
10-24 22:51:54.158 15766-15816/com.example.android.frep D/EGL_emulation: eglCreateContext: 0x9bd053c0: maj 3 min 1 rcv 4 
10-24 22:51:54.190 15766-15816/com.example.android.frep D/EGL_emulation: eglMakeCurrent: 0x9bd053c0: ver 3 1 (tinfo 0x9bd03470) 
10-24 22:51:54.190 15766-15816/com.example.android.frep E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da 
10-24 22:51:54.191 15766-15816/com.example.android.frep E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf 
10-24 22:51:54.191 15766-15816/com.example.android.frep E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824 


                      [ 10-24 22:51:54.234 15766:15816 D/   ] 
                      SurfaceInterface::setAsyncMode: set async mode 1 
10-24 22:51:54.263 15766-15816/com.example.android.frep D/EGL_emulation: eglMakeCurrent: 0x9bd053c0: ver 3 1 (tinfo 0x9bd03470) 
10-24 22:51:54.370 15766-15808/com.example.android.frep D/FA: Connected to remote service 
10-24 22:51:54.370 15766-15808/com.example.android.frep V/FA: Processing queued up service tasks: 2 
10-24 22:51:55.831 15766-15766/com.example.android.frep D/AndroidRuntime: Shutting down VM 


                      --------- beginning of crash 
10-24 22:51:55.832 15766-15766/com.example.android.frep E/AndroidRuntime: FATAL EXCEPTION: main 
                      Process: com.example.android.frep, PID: 15766 
                      java.lang.NullPointerException: Attempt to invoke interface method 'boolean java.util.List.add(java.lang.Object)' on a null object reference 
                       at com.example.android.frep.fHome$1.onDataChange(fHome.java:60) 
                       at com.google.android.gms.internal.zzbmz.zza(Unknown Source:13) 
                       at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source:2) 
                       at com.google.android.gms.internal.zzboc$1.run(Unknown Source:63) 
                       at android.os.Handler.handleCallback(Handler.java:789) 
                       at android.os.Handler.dispatchMessage(Handler.java:98) 
                       at android.os.Looper.loop(Looper.java:164) 
                       at android.app.ActivityThread.main(ActivityThread.java:6541) 
                       at java.lang.reflect.Method.invoke(Native Method) 
                       at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

Und das ist meine Modellklasse (nur Eigenschaften und Konstruktor):

public class resepNusantara { 

    private String keteranganResep; 
    private String asalDaerah; 
    private String bahan; 
    private String cara; 
    private Long rating; 
    private boolean favourite; 
    private String nama; 

    public resepNusantara() { 
     //required 
    } 

    public resepNusantara(String asalDaerah, String bahan, String cara, boolean favourite, String keteranganResep, String nama, Long rating) { 
     this.setNama(nama); 
     this.keteranganResep = keteranganResep; 
     this.asalDaerah = asalDaerah; 
     this.bahan = bahan; 
     this.cara = cara; 
     this.rating = rating; 
     this.favourite = favourite; 
    } 

Antwort

0

Sie nicht die Liste initialisiert.

Vielleicht möchten Sie es bei der Deklaration initialisieren, wie:

List<resepNusantara> listResepNusantara = new ArrayList<>(); 

Und dann Kommentar- der Zeile die Liste in der onDataChange() Methode zu löschen.

listResepNusantara.clear(); 
0

Sie erhalten diesen Absturz, weil Sie nie listResepNusantara initialisiert haben. Ersetzen Sie die Zeile

List<resepNusantara> listResepNusantara; 

von

List<resepNusantara> listResepNusantara = new ArrayList<resepNusantara>(); 

und Sie sind gut zu gehen. BTW sehen Sie auf What is a NullPointerException, and how do I fix it.

Verwandte Themen