Android - R不能解析为一个变量[重复]

时间:2023-01-18 11:28:27

Possible Duplicate:
R cannot be resolved - Android error

可能重复:R无法被解决- Android错误

I am having a issue which I have had before and I don't understand the cause. My project and code is fine as it was running yesterday. I have open Eclipse today and the whole project looks like it contains errors.

我有一个以前遇到过的问题,我不明白原因。我的项目和代码与昨天运行时一样良好。我今天打开了Eclipse,整个项目看起来包含错误。

I believe it is some sort of build path issue. I don't understand why it randomly occurs? But in the code where there is R.Layout.LayoutName there is an issue... can anyone help?

我认为这是某种构建路径的问题。我不明白为什么会随机发生?但是在有r。layout的代码中。有个问题……谁能帮忙吗?

I have tried cleaning and building it, I have tried importing android.R but I didn't have this before, it then gives and error and says the layout file doesn't exist.

我尝试过清洗和构建它,我尝试过导入android。但是我之前没有这个,它会给出错误并说布局文件不存在。

8 个解决方案

#1


74  

Are you targeting the android.R or the one in your own project?

你的目标是android吗?R还是你自己项目中的那个?

Are you sure your own R.java file is generated? Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!

你确定自己的简历吗?生成的java文件吗?xml视图中的错误可能导致R。不生成java。检查视图文件,确保所有xml都是正确的!

#2


163  

I think I found another solution to this question.

我想我找到了另一个解决这个问题的办法。

Go to Project > Properties > Java Build Path > tab [Order and Export] > Tick Android Version Checkbox Android - R不能解析为一个变量[重复] Then if your workspace does not build automatically…

转到Project > Properties > Java Build Path > tab [Order and Export] >勾选Android版本复选框,如果你的工作空间没有自动构建…

Properties again > Build Project Android - R不能解析为一个变量[重复]

属性>构建项目。

#3


21  

I've fixed the problem in my case very easy:
go to Build- Path->Configure Build Path->Order and Export and ensure that <project name>/gen folder is above <project name>/src
After fixing the order the error disappears.

我在我的案例中已经解决了这个问题非常简单:去构建- Path->配置构建路径->订单和导出,并确保 <项目名称> /gen文件夹高于 <项目名称> /src,在修复了订单后,错误消失了。

#4


12  

check your R directory ...sometimes if a file name is not all lower case and has special characters you can get this error. Im using eclipse and it only accepts file names a-z0-9_.

检查你的R目录…有时,如果文件名并非全是小写的,并且有特殊字符,您可能会得到这个错误。我在使用eclipse,它只接受文件名a-z0-9_。

#5


12  

You want Clean Project Like this

你想要像这样的清洁项目

click on

点击

Projects>Clean>select your project

this will help to u

这对你有帮助。

#6


2  

Agree it is probably due to a problem in resources that is preventing build of R.Java in gen. In my case a cut n paste had given a duplicate app name in string. Sort the fault, delete gen directory and clean.

同意这可能是由于资源的问题,阻碍了R的构建。Java,在我的例子中,剪切n粘贴给了一个重复的程序名。对故障进行排序,删除gen目录并进行清理。

#7


2  

Fought the same problem for about an hour. I finally realized that I was referencing some image files in an xml file that I did not yet have in my R.drawable folder. As soon as I copied the files into the folder, the problem went away. You need to make sure you have all the necessary files present.

在同一个问题上争论了一个小时。我终于意识到,我在xml文件中引用了一些图像文件,而在R中还没有。可拉的文件夹。我一把文件复制到文件夹中,问题就消失了。你需要确保你有所有必要的文件。

#8


0  

Save all layouts, and replace them from the previous version. Start to copy one by one and clean the project everytime, sometimes one of the layouts has something, that eclipse doesn't like. It worked for me.

保存所有布局,并将它们从以前的版本中替换。开始一个一个地复制,每次都清理项目,有时其中一个布局有eclipse不喜欢的东西。它为我工作。

#1


74  

Are you targeting the android.R or the one in your own project?

你的目标是android吗?R还是你自己项目中的那个?

Are you sure your own R.java file is generated? Mistakes in your xml views could cause the R.java not to be generated. Go through your view files and make sure all the xml is right!

你确定自己的简历吗?生成的java文件吗?xml视图中的错误可能导致R。不生成java。检查视图文件,确保所有xml都是正确的!

#2


163  

I think I found another solution to this question.

我想我找到了另一个解决这个问题的办法。

Go to Project > Properties > Java Build Path > tab [Order and Export] > Tick Android Version Checkbox Android - R不能解析为一个变量[重复] Then if your workspace does not build automatically…

转到Project > Properties > Java Build Path > tab [Order and Export] >勾选Android版本复选框,如果你的工作空间没有自动构建…

Properties again > Build Project Android - R不能解析为一个变量[重复]

属性>构建项目。

#3


21  

I've fixed the problem in my case very easy:
go to Build- Path->Configure Build Path->Order and Export and ensure that <project name>/gen folder is above <project name>/src
After fixing the order the error disappears.

我在我的案例中已经解决了这个问题非常简单:去构建- Path->配置构建路径->订单和导出,并确保 <项目名称> /gen文件夹高于 <项目名称> /src,在修复了订单后,错误消失了。

#4


12  

check your R directory ...sometimes if a file name is not all lower case and has special characters you can get this error. Im using eclipse and it only accepts file names a-z0-9_.

检查你的R目录…有时,如果文件名并非全是小写的,并且有特殊字符,您可能会得到这个错误。我在使用eclipse,它只接受文件名a-z0-9_。

#5


12  

You want Clean Project Like this

你想要像这样的清洁项目

click on

点击

Projects>Clean>select your project

this will help to u

这对你有帮助。

#6


2  

Agree it is probably due to a problem in resources that is preventing build of R.Java in gen. In my case a cut n paste had given a duplicate app name in string. Sort the fault, delete gen directory and clean.

同意这可能是由于资源的问题,阻碍了R的构建。Java,在我的例子中,剪切n粘贴给了一个重复的程序名。对故障进行排序,删除gen目录并进行清理。

#7


2  

Fought the same problem for about an hour. I finally realized that I was referencing some image files in an xml file that I did not yet have in my R.drawable folder. As soon as I copied the files into the folder, the problem went away. You need to make sure you have all the necessary files present.

在同一个问题上争论了一个小时。我终于意识到,我在xml文件中引用了一些图像文件,而在R中还没有。可拉的文件夹。我一把文件复制到文件夹中,问题就消失了。你需要确保你有所有必要的文件。

#8


0  

Save all layouts, and replace them from the previous version. Start to copy one by one and clean the project everytime, sometimes one of the layouts has something, that eclipse doesn't like. It worked for me.

保存所有布局,并将它们从以前的版本中替换。开始一个一个地复制,每次都清理项目,有时其中一个布局有eclipse不喜欢的东西。它为我工作。