我在对话框片段中使用了firebase数据库。当下面的代码运行时它会崩溃
private FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
我搜索了所有解决方案,例如更改gradle依赖项并下载google-service.json文件
等等,但问题尚未解决。我附上我的代码的所有细节请给出正确的解决方案。感谢
public class FireViewFragment extends DialogFragment {
TextView name, email, username;
Button ok;
MyDialogInterface myDialogInterface;
private FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
public FireViewFragment(MyDialogInterface myDialogInterface) {
this.myDialogInterface = myDialogInterface;
Log.d("Interface", "Constractor");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fire_view, container, false);
name = (TextView) view.findViewById(R.id.dis_name);
email = (TextView) view.findViewById(R.id.dis_email);
username = (TextView) view.findViewById(R.id.dis_uname);
ok = (Button) view.findViewById(R.id.ok);
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialogInterface.setMyDialogInterface("hi", false);
}
});
return view;
}}
的build.gradle(Module.app)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile('com.crashlytics.sdk.android:crashlytics:2.6.7@aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.google.android.gms:play-services-maps:10.2.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.google.firebase:firebase-database:9.2.0'
testCompile 'junit:junit:4.12'
}应用插件:' com.google.gms.google-services'
google-service.json文件
"project_info": {
"project_number": "961599319300",
"firebase_url": "https://working-2ab0d.firebaseio.com",
"project_id": "working-2ab0d",
"storage_bucket": "working-2ab0d.appspot.com" },
logcat的
05-01 21:56:30.298 29506-29506/com.example.gowsik.working E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.gowsik.working, PID: 29506
java.lang.NoSuchMethodError: No virtual method zzckb()Z in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.example.gowsik.working-1/split_lib_dependencies_apk.apk)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.example.gowsik.working.firebase.FireViewFragment.<init>(FireViewFragment.java:22)
at com.example.gowsik.working.activities.FirebaseActivity$2.onClick(FirebaseActivity.java:49)
at android.view.View.performClick(View.java:4780)
at android.view.View$PerformClick.run(View.java:19866)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:0)
而不是写
private FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
写
private DatabaseReference firebaseDatabase = FirebaseDatabase.getInstance();
希望这能解决您的问题
答案 1 :(得分:0)
不同版本的Google图书馆无法协同工作。您需要添加相同的版本,因此将地图库更改为9.2.0:
<?php
$link = mysqli_connect("localhost", "root", "", "applicationfestival");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
// Attempt delete query execution
$sql = " DELETE FROM billet WHERE id= $id ";
if(mysqli_query($link, $sql)){
echo "Records were deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
答案 2 :(得分:0)
问题解决了我只使用了相同版本的google-play-service和firebase依赖
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.firebase:firebase-database:9.2.0'