我开始为那条线发疯:

Java.Lang.IllegalStateException:在此过程 com.TalkAboutTv.TalkAboutTv 中未初始化默认 FirebaseApp。确保首先调用 FirebaseApp.initializeApp(Context)。

我不知道是什么原因造成的。我正在调用 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;
    }
}

}

最佳答案

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

关于android - Xamarin、Firebase : "Default FirebaseApp is not initialized in this process" - though initializeApp() is called?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44437005/

10-11 22:32