Reputation: 57
I want to recover a data to base fire.. But the application close at demmarage.
public class MainActivity extends AppCompatActivity {
private TextView mValueView;
private Firebase mRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
mValueView = (TextView) findViewById(R.id.textView);
mRef = new Firebase("https://XXXXXX.firebaseio.com/");
mRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
mValueView.setText(value);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
}
In my Firebase.class at the top there is a word: [Decompiled .class file, bytecode versio: 50.0 (java 6) [Donwload source OR Choose source).
I try to donwload source and display Studio cannot determine what kind of files the chosen items contain. Do you want to attach them as 'Sources'?]. I take (yes) and nothing happens.
I am using the implementation 'com.firebase: firebase-client-android: 2.3.1'
Thank you.
Upvotes: 0
Views: 54
Reputation: 80914
You are using a very old version, check the following link to see how to update:
https://firebase.google.com/support/guides/firebase-android
Example, change the following:
mRef = new Firebase("https://XXXXXX.firebaseio.com/");
into this:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Also you need to use the following in the root build.gradle file:
buildscript {
// ...
dependencies {
// ...
classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
}
}
allprojects {
// ...
repositories {
google() // Google's Maven repository
// ...
}
}
and in the app/build.gradle file:
apply plugin: 'com.android.application'
android {
// ...
}
dependencies {
// ...
implementation 'com.google.firebase:firebase-core:16.0.6'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
more info here:
https://firebase.google.com/docs/android/setup
The version you are using is very old, it is before google acquired firebase. Now the Firebase SDK is in the google repository (google()
).
https://dl.google.com/dl/android/maven2/index.html
Upvotes: 1