R无法解决 - Android错误 [英] R cannot be resolved - Android error

查看:220
本文介绍了R无法解决 - Android错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚下载并安装了新的Android SDK。



向导创建了这个代码:

  package eu.mauriziopz.gps; 

import android.app.Activity;
import android.os.Bundle;

public class ggps extends Activity {
/ **当活动首次创建时调用。 * /
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Eclipse 给我的错误


R无法解决

 <$> 

$ <$ p <$> c $ c> setContentView(R.layout.main);

为什么?



res / layout / 下有一个名为 main.xml 的XML文件

解决方案

除了上面的答案中的建议,请确保您的Android目标已设置:


  1. 选择属性

  2. 在左侧菜单中选择Android

  3. <


>编辑:一年后,我发现另一个原因。我在我的drawable文件夹中有一个.jpg图像与.png图像同名。在我的代码中引用此图像必须混淆程序,它给出了R无法解决的错误。


I just downloaded and installed the new Android SDK. I wanted to create a simple application to test drive it.

The wizard created this code:

package eu.mauriziopz.gps;

import android.app.Activity;
import android.os.Bundle;

public class ggps extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

but Eclipse gives me the error

R cannot be resolved

on line

setContentView(R.layout.main);

Why?

PS: I do have an XML file named main.xml under res/layout/.

解决方案

Along with the great suggestions in the previous answers, make sure your Android target is set:

  1. Right-click on your project
  2. Choose Properties
  3. Choose Android in the left menu
  4. Tick a box next to the appropriate Project Build Target.
  5. Click Apply and OK

Edit: A year later I found another cause. I had a .jpg image in my drawable folder with the same name as a .png image. Referencing this image in my code must have confused the program and it gave the "R cannot be resolved" error.

这篇关于R无法解决 - Android错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆