当我添加这个
demoRef = FirebaseDatabase.getInstance().getReference().child("txt");
我的应用程序崩溃,当我删除它时,应用程序工作可以有人帮助我。
我尝试了很多方法,比如更改数据库的版本,但没有任何效果,我花了 3 多周的时间没有任何解决
这是我的主要活动
公共类 MainActivity 扩展 Activity {
private HashMap <String,Object>map=new HashMap();
private Button send;
private EditText edit;
private DatabaseReference demoRef;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
FirebaseApp.initializeApp(this);
demoRef = FirebaseDatabase.getInstance().getReference().child("txt");
send=findViewById(R.id.mainButton1);
edit=findViewById(R.id.mainEditText1);
}
}
这是我的构建
dependencies {
//compile 'com.google.firebase:firebase-database:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-database:16.0.1'
compile 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
这是我的 Logcat
FATAL EXCEPTION: main
Process: com.firebase, PID: 5291
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firebase/com.firebase.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.firebase.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:6677)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
... 9 more
Shutting down VM
FATAL EXCEPTION: main
Process: com.firebase, PID: 8039
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.firebase/com.firebase.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2789)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.firebase.MainActivity.onCreate(MainActivity.java:27)
at android.app.Activity.performCreate(Activity.java:6677)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2677)
... 9 more