使用NBAndroid的NetBeans不能找到symbol setContentView(r.l yout.main);

时间:2021-03-14 20:52:33

I recently installed NetBeans 7.1.1 with NBAndroid 1.11 plugin. After starting a new HelloWorld project, I get the following error from the test code:

我最近安装了NetBeans 7.1.1和NBAndroid 1.11插件。启动一个新的HelloWorld项目后,我从测试代码中得到以下错误:

C:\Users\Daniel\Documents\NetBeansProjects\HelloWorld\src\Hello\World\HelloWorldMain.java:14: error: cannot find symbol setContentView(R.layout.main);

C:\Users\Daniel\Documents\ NetBeansProjects \ HelloWorld \ src \ Hello \ \ HelloWorldMain世界。错误:无法找到符号setContentView(R.layout.main);

Here is my source code for HelloWorldMain.java file:

这是我的HelloWorldMain源代码。java文件:

package Hello.World;

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

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

The setContentView function is causing the problem for some reason. I checked the R.java file for any errors and didn't seem to find any:

setContentView函数由于某种原因导致了问题。我检查了R。java文件的任何错误,似乎没有找到任何:

/* AUTO-GENERATED FILE.  DO NOT MODIFY.
 *
 * This class was automatically generated by the
 * aapt tool from the resource data it found.  It
 * should not be modified by hand.
 */

package Hello.World;

public final class R {
    public static final class attr {
    }
    public static final class layout {
        public static final int main=0x7f020000;
    }
    public static final class string {
        public static final int app_name=0x7f030000;
    }
}

Any help would be appreciated.

如有任何帮助,我们将不胜感激。

2 个解决方案

#1


25  

You need to remove import android.R;. Your R and android.R are two different classes.

您需要删除导入的android.R;你的R和android。R是两个不同的类。

#2


9  

In Android, we dont have a class that is auto-generated, so, if you doesnt find your R class try to build your project or to run it. After that you can find that a new package was added to your project, there is where you can find your R class.

在Android中,我们没有自动生成的类,所以,如果没有找到R类,请尝试构建项目或运行它。之后你可以发现一个新的包被添加到你的项目中,在那里你可以找到你的R类。

#1


25  

You need to remove import android.R;. Your R and android.R are two different classes.

您需要删除导入的android.R;你的R和android。R是两个不同的类。

#2


9  

In Android, we dont have a class that is auto-generated, so, if you doesnt find your R class try to build your project or to run it. After that you can find that a new package was added to your project, there is where you can find your R class.

在Android中,我们没有自动生成的类,所以,如果没有找到R类,请尝试构建项目或运行它。之后你可以发现一个新的包被添加到你的项目中,在那里你可以找到你的R类。