Android 资源 ID 突然不是最终的,无法解析字段 [英] Android resource IDs suddenly not final, fields cannot be resolved
问题描述
我正在开发一个新旧项目...我正在为不同的国家/地区市场制作它,当我从旧项目中复制我的代码时,它显示了一些错误,例如 MIGRATE ANDROID 代码(截至 ADT 14,资源字段不能用作切换案例.)这发生在 strings.xml 文件中的资源和布局中.但它没有给我一些可能的修复......我该如何修复它????这是代码:
I'm working on a new-old project... I'm making it for a different country market, and when i copyed my code from an old project it shows some mistake like MIGRATE ANDROID CODE (As of ADT 14, resource fields cannot be used as switch cases.) This happens for a resourses that are in strings.xml file and for layout. But it doesn't give me some posible fix... how can i fix it???? Here is code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Here is mistake
setContentView(R.layout.main);
//Kreira AlertDialog sa dva dugmeta koji ce se pojaviti pri aktiviranju aplikacije
ad = new AlertDialog.Builder(this).create();
//And HERE
ad.setTitle(getString(R.string.vasa_trenutna_lokacija));
//And HERE
ad.setMessage(getString(R.string.da_bi_ste_koristili_aplikaciju));
//And HERE
ad.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dozvoli), new DialogInterface.OnClickListener() {
//Klikom na dugme Dozvoli otvara se novi prozor
@Override
public void onClick(DialogInterface ad, int which) {
Intent i = new Intent(NiskiMerakActivity.this, TrenutnaLokacija.class);
startActivity(i);
finish();
}
});
ad.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.ne_dozvoli),new DialogInterface.OnClickListener() {
//Klikom na dugme Ne dozvoli aplikacija se zatvara
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
推荐答案
从 ADT 14 开始,资源字段不能用作切换案例.
As of ADT 14, resource fields cannot be used as switch cases.
这也发生在我身上,即使我没有在 switch 语句中使用 R 变量,我也收到了这个错误.不要被错误信息误导.您基本上有一些与 R.java 文件相关的错误.确保您没有导入 R.java,因为您应该拥有自己的.删除 R.java 文件,构建项目,然后查看是否生成了 R.java 文件.如果没有,您可能会遇到阻止更新 R.java 文件的错误.尝试 Project > Clean 以查找任何错误.消除错误并重建项目,以便生成 R.java 文件并保持最新.
This happened to me too, I got this error even though I wasn't using the R variable in a switch statement. Don't be mislead by the error message. You basically have some error that relates to the R.java file. Make sure you don't import R.java since you should have your own. Delete your R.java file, build project, and see if your R.java file gets generated. If not, you could have an error that is preventing your R.java file from being updated. Try Project > Clean to find any errors. Get rid of the errors and rebuild your project so that your R.java file gets generated and is up-to-date.
这篇关于Android 资源 ID 突然不是最终的,无法解析字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!