Android studio crash with firebase database on hello world example

问题: I have this code: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(sav...

问题:

I have this code:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FirebaseDatabase database = FirebaseDatabase.getInstance();
        DatabaseReference myRef = database.getReference("message");

        myRef.setValue("Hello, World!");
    }
}

and in build.gradle have this problem:

enter image description here

The problem is: Every time I run this application he crashes. And I don't know why this is happening, I need help with this problem.

Logcat:

enter image description here


回答1:

You need implement this: implementation 'com.google.firebase:firebase-core:16.0.7'

Update

Add FirebaseApp.initializeApp(this); in your application class.

Create class extends Application

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
    }
}

In Android Manifest:

<application
    android:name=".MyApplication">
</application>
  • 发表于 2019-03-03 18:01
  • 阅读 ( 213 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除