问题描述
我刚开始按照这个文档建立我的Android应用:
建立图书馆和权限后,我开始输入code的非常几行。我立刻得到了编译错误的列表如下图所示:
我再试着输入dataRef。和CTR +空格,没有默认的建议,但一个红色的消息说dataRef不能被解析为一个类型。 dataRef是参考火力数据库(就像一个在文档的片段)
那么,什么是错的?
PS:我也尝试清洗项目。
我相信我的火力地堡库是最新的,正如它的名字是火力点 - 客户端JVM的最新的我只是今天下载了它。
我din't添加任何XML或建造任何东西。
下面是我的MainActivity.java:
包com.biz.nah;进口com.firebase.client.DataSnapshot;
进口com.firebase.client.Firebase;进口android.os.Bundle;
进口android.app.Activity;
进口android.view.Menu;公共类MainActivity延伸活动{ @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main); //创建数据库的引用
字符串URL =https://nah.firebaseio.com;
火力地堡dataRef =新的火力点(URL); dataRef.addListenerForSingleValueEvent(新ValueEventListener(){
@覆盖
公共无效onDataChange(DataSnapshot快照){
//做一些东西,一旦
} @覆盖
公共无效onCancelled(){
通信System.err.println(监听器被取消);
}
});
} @覆盖
公共布尔onCreateOptionsMenu(菜单菜单){
//充气菜单;如果是present这增加了项目操作栏。
。getMenuInflater()膨胀(R.menu.main,菜单);
返回true;
}
}
在code相貌端正,虽然你的Eclipse窗口的截图证明并非如此。
该错误听起来像日食是不是您解析code正确。
另一条线索到这一点,是在大纲视图网址
和 dataref
显示为 MainActivity
的字段,而不是函数变量,就像你在code公布。
尝试:
- 关闭和打开Eclipse
- 项目 - >清除
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;
}
}
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:
- Close and open Eclipse
- Project -> Clean
这篇关于火力地堡参考对象不能被解析为一个类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!