gpt4 book ai didi

java - 应用程序连接到 Firebase 时程序崩溃

转载 作者:行者123 更新时间:2023-12-01 19:53:01 25 4
gpt4 key购买 nike

应用连接到 Firebase 时程序崩溃。我更新了SDK,但是不起作用。

我只有一项 Activity 失败。是这样的:

public class MainActivity extends AppCompatActivity {

private Button btn_save_data;
private EditText e_name;
private FirebaseDatabase firebaseDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e_name = (EditText) findViewById(R.id.name);
btn_save_data = (Button) findViewById(R.id.save_data);
btn_save_data.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String name = e_name.getText().toString();
firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference myRef = firebaseDatabase.getReference("users");
myRef.setValue(name);
}
});
}

}

构建.gradle

 apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
applicationId "adais.mywayapp"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-messaging:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'

错误详细信息:

06-03 23:31:33.272 8908-8908/adais.mywayapp W/dalvikvm: VFY: unable to resolve virtual method 26689: Lcom/google/firebase/FirebaseApp;.zzbqo ()Z
06-03 23:31:33.272 8908-8908/adais.mywayapp D/dalvikvm: VFY: replacing opcode 0x6e at 0x0081
06-03 23:31:33.284 8908-8908/adais.mywayapp D/AndroidRuntime: Shutting down VM
06-03 23:31:33.284 8908-8908/adais.mywayapp W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41874ce0)
threadid=1: uncaught exception occurred
06-03 23:31:33.288 8908-8908/adais.mywayapp W/System.err: java.lang.NoSuchMethodError: com.google.firebase.FirebaseApp.zzbqo
06-03 23:31:33.293 8908-8908/adais.mywayapp W/System.err: at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at adais.mywayapp.MainActivity$1.onClick(MainActivity.java:26)
at android.view.View.performClick(View.java:4463)
at android.view.View$PerformClick.run(View.java:18789)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
06-03 23:31:33.294 8908-8908/adais.mywayapp W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
06-03 23:31:33.295 8908-8908/adais.mywayapp W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
06-03 23:31:33.295 8908-8908/adais.mywayapp W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
06-03 23:31:33.306 8908-8908/adais.mywayapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: adais.mywayapp, PID: 8908
java.lang.NoSuchMethodError: com.google.firebase.FirebaseApp.zzbqo
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at adais.mywayapp.MainActivity$1.onClick(MainActivity.java:26)
at android.view.View.performClick(View.java:4463)
at android.view.View$PerformClick.run(View.java:18789)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:641)
at dalvik.system.NativeStart.main(Native Method)
06-03 23:31:34.778 8908-8908/adais.mywayapp I/Process: Sending signal. PID: 8908 SIG: 9

最佳答案

您正在使用旧版本和新版本的 Firebase 依赖项,因此请使用此处提到的最新版本

Firebase Android Release Notes

例如使用

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.0.1'
//...other
}

关于java - 应用程序连接到 Firebase 时程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50670596/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com