Using Eclipse on win XP. I've previously created an app or 2, but am now working on the 'real' version and get the above error.
在win XP上使用Eclipse。我之前创建过一个或两个应用程序,但现在正在开发“真实”版本,并得到上面的错误。
I was having funnies creating a 1.5 version, so have started a new project for 2.1.
我制作了一个1.5版本,所以已经开始了一个2.1版本的新项目。
package xxx.guest;
import android.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class briefme extends Activity {
private String strURL;
........
........
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main );
Project as below (note I've removed some names for confidentiality reasons!)
项目如下(注意,由于保密原因,我删除了一些名称!)
Any ideas what's gone wrong?
有什么问题吗?
Thanks,
谢谢,
Martin.
马丁。
项目截图在这里
8 个解决方案
#1
59
I would try refreshing, if that doesnt work, close and open the project.
如果不奏效,我将尝试刷新,关闭并打开项目。
If those two fail, delete and re-create R(it should auto-generate)(copy it just to be on the safe side).
如果这两个都失败了,删除并重新创建R(它应该自动生成)(为了安全起见,复制它)。
I've have this happen to me a few times and those are the three things I usually do to fix the error.
我有过几次这样的情况这是我修复错误的三种方法。
Edit: Also try changing your import:
编辑:也可以尝试改变你的导入:
import android.R;
to:
:
import your.package.R;
#2
3
In my case this happened because their was a layout resource with upper case letters in the file name. Resources weren't compiled because of the error and because of that the R class was missing.
在我的例子中,这是因为它们是一个布局资源,在文件名中包含大写字母。由于错误和R类丢失,资源没有被编译。
#3
2
As suggested above, simply changing the import "import android.R;" to one relative to your app e.g. "import your.package.name.R;" should do the trick here.
如上所述,只需将“导入android.R”改为相对于您的应用程序的一个。“导入你的。package. name.r。”
#4
1
You can also check if adb program in /platform-tools folder has permissions to run in your system. If not, the R.java for your project won't be generated.
您还可以检查/platform-tools文件夹中的adb程序是否具有在系统中运行的权限。如果不是,R。您的项目不会生成java。
#5
0
My two cents.
我的两个美分。
In my case, i had used another variable with the same name R which resulted in compilation error. Eclipse could get better in terms of guiding the users with the exact error message.
在我的例子中,我使用了另一个名称为R的变量,这导致了编译错误。Eclipse可以更好地指导用户使用准确的错误消息。
#6
0
Possible duplicate of R cannot be resolved - Android error.
无法解决R的可能重复- Android错误。
In that thread we have an excellent answer.
在这条线索中,我们有一个极好的答案。
Referring to http://source.android.com/source/using-eclipse.html we get the following snippet:
参考http://source.android.com/source/using-eclipse.html,我们得到以下代码片段:
Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask Eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.
注意:Eclipse有时喜欢添加“导入android”。使用资源的文件顶部的R"语句,特别是当您要求Eclipse对导入进行排序或管理时。这将使你崩溃。注意这些错误的导入语句并删除它们。
So the answer is to delete rather than rename your import android.R;
所以答案是删除而不是重命名导入android.R;
The reason for this is that your.package.R
is visible since you share package. The import android.R;
masks this, so it is cleaner to delete this rather than changing it to something redundant.
原因是你的包裹。R是可见的,因为您共享包。导入android.R;将其隐藏,这样就可以将其删除,而不是将其更改为冗余。
#7
0
If you have 64 bit Linux platform without ia32 libraries, then this problem could also occur. It took me quite some time to pin this one down, seeing that the problem is not clearly linked with the inability to execute 32 bit code.
如果您有64位的Linux平台而没有ia32库,那么这个问题也会发生。我花了很长时间才确定这一点,因为问题并没有明显地与无法执行32位代码联系在一起。
#8
0
In my case (seeing other tutorials) you have to change:
在我的例子中(看其他教程)你必须改变:
setContentView(R.layout.main );
To:
:
setContentView(R.layout.activity_main);
#1
59
I would try refreshing, if that doesnt work, close and open the project.
如果不奏效,我将尝试刷新,关闭并打开项目。
If those two fail, delete and re-create R(it should auto-generate)(copy it just to be on the safe side).
如果这两个都失败了,删除并重新创建R(它应该自动生成)(为了安全起见,复制它)。
I've have this happen to me a few times and those are the three things I usually do to fix the error.
我有过几次这样的情况这是我修复错误的三种方法。
Edit: Also try changing your import:
编辑:也可以尝试改变你的导入:
import android.R;
to:
:
import your.package.R;
#2
3
In my case this happened because their was a layout resource with upper case letters in the file name. Resources weren't compiled because of the error and because of that the R class was missing.
在我的例子中,这是因为它们是一个布局资源,在文件名中包含大写字母。由于错误和R类丢失,资源没有被编译。
#3
2
As suggested above, simply changing the import "import android.R;" to one relative to your app e.g. "import your.package.name.R;" should do the trick here.
如上所述,只需将“导入android.R”改为相对于您的应用程序的一个。“导入你的。package. name.r。”
#4
1
You can also check if adb program in /platform-tools folder has permissions to run in your system. If not, the R.java for your project won't be generated.
您还可以检查/platform-tools文件夹中的adb程序是否具有在系统中运行的权限。如果不是,R。您的项目不会生成java。
#5
0
My two cents.
我的两个美分。
In my case, i had used another variable with the same name R which resulted in compilation error. Eclipse could get better in terms of guiding the users with the exact error message.
在我的例子中,我使用了另一个名称为R的变量,这导致了编译错误。Eclipse可以更好地指导用户使用准确的错误消息。
#6
0
Possible duplicate of R cannot be resolved - Android error.
无法解决R的可能重复- Android错误。
In that thread we have an excellent answer.
在这条线索中,我们有一个极好的答案。
Referring to http://source.android.com/source/using-eclipse.html we get the following snippet:
参考http://source.android.com/source/using-eclipse.html,我们得到以下代码片段:
Note: Eclipse sometimes likes to add an "import android.R" statement at the top of your files that use resources, especially when you ask Eclipse to sort or otherwise manage imports. This will cause your make to break. Look out for these erroneous import statements and delete them.
注意:Eclipse有时喜欢添加“导入android”。使用资源的文件顶部的R"语句,特别是当您要求Eclipse对导入进行排序或管理时。这将使你崩溃。注意这些错误的导入语句并删除它们。
So the answer is to delete rather than rename your import android.R;
所以答案是删除而不是重命名导入android.R;
The reason for this is that your.package.R
is visible since you share package. The import android.R;
masks this, so it is cleaner to delete this rather than changing it to something redundant.
原因是你的包裹。R是可见的,因为您共享包。导入android.R;将其隐藏,这样就可以将其删除,而不是将其更改为冗余。
#7
0
If you have 64 bit Linux platform without ia32 libraries, then this problem could also occur. It took me quite some time to pin this one down, seeing that the problem is not clearly linked with the inability to execute 32 bit code.
如果您有64位的Linux平台而没有ia32库,那么这个问题也会发生。我花了很长时间才确定这一点,因为问题并没有明显地与无法执行32位代码联系在一起。
#8
0
In my case (seeing other tutorials) you have to change:
在我的例子中(看其他教程)你必须改变:
setContentView(R.layout.main );
To:
:
setContentView(R.layout.activity_main);