Reputation: 2211
I just start building my Android app by following this docs: https://www.firebase.com/docs/reading-data.html
After setting up libraries and permission, I start typing the very few lines of code. And immediately I got a list of compile errors as shown below:
I then tried typing "dataRef." and Ctr+Space, there was no Default Proposals but a a red message saying "dataRef can not be resolved to a type". dataRef is the reference to firebase database (just like the one in the docs's snippet)
So what was wrong?
Ps: I also tried cleaning the project. I believe that my Firebase library is the latest, as its name is "firebase-client-jvm-LATEST" and I just downloaded it today. I din't add any xml or build anything yet. Below is my MainActivity.java:
package com.biz.nah;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a reference to database
String url = "https://nah.firebaseio.com";
Firebase dataRef = new Firebase(url);
dataRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
// Do some stuff once
}
@Override
public void onCancelled() {
System.err.println("Listener was cancelled");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Upvotes: 1
Views: 3540
Reputation: 623
The code looks correct, although the screenshot of your eclipse window prove otherwise.
The errors sound like eclipse isn't parsing your code correctly.
Another clue to this, is in the outline view url
and dataref
are shown as MainActivity
's fields rather than function variables, like you posted in your code.
Try:
Upvotes: 1