这是 Why is my layout unable to be resolved? (Android/Java) 的延续(阅读第一个答案的评论)因为我需要发布大量代码,而在评论中这样做是行不通的。
package scouting.form;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
public class Scouting extends Activity {
CheckBox sground,strough,shigh,dground,dtrough,dhigh;
Button logout,clr;
EditText TeamNum;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scouting);
TeamNum=(EditText) findViewById(R.id.TBTeamNum);
sground=(CheckBox) findViewById(R.id.CBSGround);
dground=(CheckBox) findViewById(R.id.CBDGround);
strough=(CheckBox) findViewById(R.id.CBSTrough);
dtrough=(CheckBox) findViewById(R.id.CBDTrough);
shigh=(CheckBox) findViewById(R.id.CBSHigh);
dhigh=(CheckBox) findViewById(R.id.CBDHigh);
logout=(Button) findViewById(R.id.Logout);
logout.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
clr=(Button) findViewById(R.id.CLREntries);
clr.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
sground.setActivated(false);
strough.setActivated(false);
shigh.setActivated(false);
dground.setActivated(false);
dtrough.setActivated(false);
dhigh.setActivated(false);
}
});
}
@Override public void onBackPressed(){}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_scouting, menu);
return true;
}
}
每一行带有“R.xxx.xxx”的内容都表示“R 无法解析为变量”。
我尝试进行清理,因为这几乎肯定是 Eclipse 中的一个小故障,所以我尝试导入 android.R,保存并清理,然后取消导入 android.R(导入 android.R 会破坏处理它的所有内容,但我故意这样做),保存并清理,希望“刷新”它以消除故障。我也尝试过重新启动 Eclipse。仍然存在这个错误。
最佳答案
我修好了!所以我在原始文件夹中有这个名为“Gangam Style.mp3”的文件(我不知道它是如何到达那里的)。我注意到一个错误,指出该名称无效。我进入该文件夹并删除该文件,所有错误都消失了。我猜想 Eclipse 有一个坏文件,无论出于什么原因,它都找不到 R。
对于任何收到 R 无法解析错误的人,请确保您没有导入“android.R”,并确保您的任何文件夹中没有任何名称无效的文件。
关于java - 为什么会发生这个 R 故障(Eclipse Android Java)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13241769/