应用程序只是打开和关闭,即使我初始化上下文(火力地堡)

时间:2019-02-02 22:48:50

标签: java android firebase kotlin firebase-authentication

因此,我试图启动并运行我的第一个应用程序,尝试在手机上对其进行调试时遇到问题。 的错误状态

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.stuff.morestuff. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:1)
        at com.stuff.morestuff.MainActivity.<init>(MainActivity.java:13)

我尝试使用FirebaseApp.initializeApp(this),但仍然会引发相同的错误。

public class MainActivity extends AppCompatActivity {

    private FirebaseAuth mAuth;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //I've tried using this too but it didn't change anything, still the same error
        //FirebaseApp.initializeApp(this);
        mAuth = FirebaseAuth.getInstance();
    }

    @Override
    public void onStart() {
        super.onStart();
        // Check if user is signed in (non-null) and update UI accordingly.
        FirebaseUser currentUser = mAuth.getCurrentUser();

        if(currentUser == null){
            Intent startIntent = new Intent(MainActivity.this, StartActivity.class);
            startActivity(startIntent);
        }
    }
}

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

此解决方案对我有用。 **备注如果要使用 public simplePOVgames: ICommonGameCard[] = []; private addGameCard(gamecard: ICommonGameCard): void { gamecard.pov === POVType.Simple ? this.simplePOVgames.push(gamecard) : this.freePOVgames.push(gamecard); }

,请检查对解决方案的评论

https://stackoverflow.com/a/52136056/7808468