您好,很抱歉,如果這個問題很明顯,但是自從兩天以來,我遇到了空指針異常E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.myapplicationteeeeeeeeeest, PID: 13439 java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.ArrayList.add(int, java.lang.Object)' on a null object reference at com.example.myapplicationteeeeeeeeeest.ui.FSettings.SettingsFragment$4.onDataChange(SettingsFragment.java:336) at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.0.0:179) at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.0.0:75) at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.0.0:63) at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.0.0:55) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)I/Process: Sending signal. PID: 13439 SIG: 9Disconnected from the target VM, address: 'localhost:8617', transport: 'socket'我知道 Firebase 是異步的,返回值為 null,但它是隨機(jī)來來去去的。這是它所使用的類。如果有人知道為什么會發(fā)生這種情況那就太好了,我們多年來一直致力于解決這個問題,但似乎無法解決它。提前致謝!
1 回答

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗 獲得超4個贊
看起來您的代碼從未調(diào)用initIngredients()
來創(chuàng)建數(shù)據(jù)庫回調(diào)所需的所有 ArrayList 對象。它們最初都是空的,嘗試向其中之一添加某些內(nèi)容將導(dǎo)致該錯誤。
添加回答
舉報
0/150
提交
取消