當我使用以下代碼...並按下應用程序中的刪除按鈕時,該值會在Firebase數據庫中刪除,但會導致我的應用程序崩潰。使用removeValue()時,Firebase應用程序崩潰
mSingleRemoveBtn.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view)
{
if(mPostKey!=null)
{
System.out.println("The key is " + mPostKey);
mDatabase.child(mPostKey).removeValue();
Intent mainIntent = new Intent(BlogSingleActivity.this, MainActivity.class);
startActivity(mainIntent);
}
else
{
System.out.println("The key is empty");
}
}
此外,當我刪除「mDatabase.child(mPostKey).removeValue();」,該應用程序工作正常,但顯然不能從我的數據庫中刪除條目。
logcat的
08-01 19:42:51.093 32536-32536/com.vks_apps.blogs I/System.out: The key is -KqT82kPqOE_iq0UKHnm
--------- beginning of system
08-01 19:42:51.129 32536-4494/com.vks_apps.blogs V/FA: Inactivity, disconnecting from the service
08-01 19:42:51.131 32536-32536/com.vks_apps.blogs D/AndroidRuntime: Shutting down VM
08-01 19:42:51.132 32536-32536/com.vks_apps.blogs E/UncaughtException: java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source)
at com.vks_apps.blogs.BlogSingleActivity$1.onDataChange(BlogSingleActivity.java:88)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
08-01 19:42:51.135 32536-4494/com.vks_apps.blogs D/FA: Logging event (FE): _ae, Bundle[{_o=crash, _sc=BlogSingleActivity, _si=-4635728123048285128, timestamp=1501596771132, fatal=1}]
08-01 19:42:51.157 32536-4494/com.vks_apps.blogs V/FA: Using measurement service
08-01 19:42:51.157 32536-4494/com.vks_apps.blogs V/FA: Connecting to remote service
--------- beginning of crash
08-01 19:42:51.378 32536-32536/com.vks_apps.blogs E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.vks_apps.blogs, PID: 32536
java.lang.NullPointerException: Can't pass null for argument 'pathString' in child()
at com.google.firebase.database.DatabaseReference.child(Unknown Source)
at com.vks_apps.blogs.BlogSingleActivity$1.onDataChange(BlogSingleActivity.java:88)
at com.google.android.gms.internal.zzbmz.zza(Unknown Source)
at com.google.android.gms.internal.zzbnz.zzYj(Unknown Source)
at com.google.android.gms.internal.zzboc$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
08-01 19:42:51.445 32536-5218/com.vks_apps.blogs I/FirebaseCrash: Sending crashes
08-01 19:42:52.021 32536-5218/com.vks_apps.blogs I/FirebaseCrash: Response code: 200
08-01 19:42:52.023 32536-5218/com.vks_apps.blogs I/FirebaseCrash: Report sent with crash report id: 6e22679504000000
鑑於堆棧跟蹤中問題的來源,您可以在代碼中指出'BlogSingleActivity.java:88'嗎? –
Vipul,請不要垃圾評論與您的其他問題的鏈接。你已經完成了幾個地方,這裏和下面的答案。這對其他用戶和我們的規則很惱人。如果有人想要查找其他問題,他們可以查看您的個人資料中列出的所有問題。 –