我已经尝试了太多寻找解决方案的方法,但是没有解决方案解决了我的问题!

我的应用程序运行正常,但我想将TextView中的结果添加到Firebase。
将Firebase添加到Java代码后,应用程序崩溃并显示消息“App Unfotunatlly stop”,然后在真实设备上打开该应用程序!

这是添加了Firebase的Java代码:

public class MainActivity extends AppCompatActivity implements LocationListener ,ValueEventListener {

//here is the added firebase that cause the error -_-
FirebaseDatabase database = FirebaseDatabase.getInstance();
private DatabaseReference myRef = database.getReference();
private DatabaseReference buslocationRef = myRef.child("master");

Button getLocationBtn;
TextView locationText, test1;

LocationManager locationManager;

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

}
}

和我的build.gradle:
dependencies {

compile 'com.android.support:appcompat-v7:26.1.0'

compile 'com.google.firebase:firebase-database:12.0.1'
}

另外,我已经将Android Studio更新到了最新版本3.0!

希望您能帮到我。
提前致谢。

最佳答案

尝试在build.gradle(项目版本)中将google-services版本更改为4.2.0。

10-05 20:43
查看更多