Firebase 函数不会触发实时数据库

时间:2021-06-30 07:44:52

标签: android firebase firebase-realtime-database google-cloud-functions

Firebase 函数不会为实时数据库触发。它给出了 gettoken() 空指针异常。谁能告诉我这是什么意思。我在这段代码中被困了一周。它发生在我更新了所有依赖项之后。

com.google.android.gms.tasks.RuntimeExecutionException: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String com.google.firebase.iid.internal.FirebaseInstanceIdInternal.getToken()' on a null object reference
        at com.google.android.gms.tasks.zzw.getResult(com.google.android.gms:play-services-tasks@@17.2.1:3)
        at com.example.messenger.RegisterphoneActivity$6$1.onComplete(RegisterphoneActivity.java:461)
        at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@17.2.1:1)
        at android.os.Handler.handleCallback(Handler.java:869)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at android.os.Looper.loop(Looper.java:206)
        at android.app.ActivityThread.main(ActivityThread.java:6784)
        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:852)
     Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String com.google.firebase.iid.internal.FirebaseInstanceIdInternal.getToken()' on a null object reference
        at com.google.firebase.functions.FirebaseContextProvider.lambda$getContext$2$FirebaseContextProvider(FirebaseContextProvider.java:66)
        at com.google.firebase.functions.-$$Lambda$FirebaseContextProvider$JpPWfEIwsUrrbB9R-dUWAHi9zJo.then(Unknown Source:8)
        at com.google.android.gms.tasks.zzo.run(com.google.android.gms:play-services-tasks@@17.2.1:1)
        at android.os.Handler.handleCallback(Handler.java:869) 
        at android.os.Handler.dispatchMessage(Handler.java:101) 
        at android.os.Looper.loop(Looper.java:206) 
        at android.app.ActivityThread.main(ActivityThread.java:6784) 
        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:852) 

这是我的 index.js

import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();


export const createaccount = functions.https.onCall((data) => {
 
  return admin.database().ref("/signupuser/"+data.phone).set( {
    phv: false,
    t: data.time,
    si: false,
  }).then(()=> {
    console.log("New account created");
    // const data=snapshot.data();
    // response.send(data);
    return "success";
  }).catch((error)=> {
    throw new functions.https.HttpsError("unknown", error.message, error);
  });
});
 private Task<String> addaccount(String text) {

        Log.e("check addmessage:","code is here addaccount");
        // Create the arguments to the callable function.
        Map<String, Object> data = new HashMap<>();
           data.put("phone", text);
           data.put("time", ServerValue.TIMESTAMP);
        return mFunctions
                .getHttpsCallable("createaccount")
                .call(data)
                .continueWith(new Continuation<HttpsCallableResult, String>() {
                    @NonNull
                    @Override
                    public String then(@NonNull Task<HttpsCallableResult> task) throws Exception {
                        // This continuation runs on either success or failure, but if the task
                        // has failed then getResult() will throw an Exception which will be
                        // propagated down.
                        String result = (String) task.getResult().getData();
                        assert result != null;
                        Log.e("cloud function result:",result);
                        return result;
                    }
                });
    }


'com.google.firebase.iid.internal.FirebaseInstanceIdInternal.getToken()' 当我尝试记录下面 task.getresult() 的值时发生空指针异常

 addaccount(phonenumberwithoutplus).addOnCompleteListener(new OnCompleteListener<String>() {
                            @Override
                            public void onComplete(@NonNull Task<String> task)
                            {
                                Log.e("check addmessage:","code is here complete"+task.getResult());
                                unregisterReceiver(r1);
                                if (!task.isSuccessful())
                                {
                                    Exception e = task.getException();
                                    if (e instanceof FirebaseFunctionsException)
                                    {
                                        FirebaseFunctionsException ffe = (FirebaseFunctionsException) e;
                                        FirebaseFunctionsException.Code code = ffe.getCode();
                                        Object details = ffe.getDetails();
                                        Log.e("check addmessage:","code is here"+details.toString());
                                    }
                                    registerbtn.setText("GO");
                                    progressbarregister.setVisibility(View.GONE);
                                }else
                                {
                                    Log.e("check addmessage:","code is here");
                                    readphoneverify();
                                 //   registerbtn.setText("GO");
                                 //   progressbarregister.setVisibility(View.GONE);
                                }
                            }
                        });

在我更新依赖项之前,上面的代码有效。我将所有依赖项更新到最新版本。我已经卡了一个多星期了。我不知道我哪里出错了。请有人帮我清除这个错误。

0 个答案:

没有答案
相关问题