当前位置: 首页 > 知识库问答 >
问题:

Xamarin,Firebase:“默认的FirebaseApp没有在此进程中初始化”-尽管调用了initializeApp()?

祁俊喆
2023-03-14

我开始为那句话发疯了:

IllegalStateException:默认FirebaseApp未在此进程中初始化com.talkabouttv.talkaboutTV。确保首先调用FirebaseApp.InitializeApp(上下文)。

我不知道是什么引起的。我正在调用firebaseapp.intapp(this),我的包名匹配...为什么它不能工作?

protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
}



protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView (Resource.Layout.Main);

    firebase = new FirebaseClient("2131099704");
    Firebase.FirebaseApp.InitializeApp(this);

    FirebaseDatabase.Instance.GetReference("chats").AddValueEventListener(this);

    fab = FindViewById<Button>(Resource.Id.fab);
    edtChat = FindViewById<EditText>(Resource.Id.input);
    lstChat = FindViewById<ListView>(Resource.Id.list_of_messages);


    fab.Click += delegate
    {

        PostMessage();
    };



    if (FirebaseAuth.Instance.CurrentUser == null)
        StartActivityForResult(new Android.Content.Intent(this, typeof(SignIn)), MyResultCode);
    else
    {
        Toast.MakeText(this, "Welcome " + FirebaseAuth.Instance.CurrentUser.Email, ToastLength.Short).Show();
        DisplayChatMessage();
    }
}

private async void PostMessage()
{
    var items = await firebase.Child("chats").PostAsync(new MessageContent(FirebaseAuth.Instance.CurrentUser.Email, edtChat.Text));
    edtChat.Text = "";
}

public void OnCancelled(DatabaseError error)
{

}

public void OnDataChange(DataSnapshot snapshot)
{
    DisplayChatMessage();
}

private async void DisplayChatMessage()
{
    lstMessage.Clear();
    var items = await firebase.Child("chats")
        .OnceAsync<MessageContent>();

    foreach (var item in items)
        lstMessage.Add(item.Object);
    ListViewAdapter adapter = new ListViewAdapter(this, lstMessage);
    lstChat.Adapter = adapter;
    }
}

}

共有1个答案

梁鸿风
2023-03-14

尝试在应用程序类中初始化firebase(OnCreate方法)。但是首先从项目控制台下载google-services.json文件,并确保它具有“GoogleServicesJSON”值作为构建操作。

 类似资料: