Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetBeans with NBAndroid - cannot find symbol setContentView(R.layout.main);

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:

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

Here is my source code for HelloWorldMain.java file:

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:

/* 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.

like image 801
Daniel Harris Avatar asked Mar 21 '12 06:03

Daniel Harris


2 Answers

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

like image 60
MByD Avatar answered Oct 06 '22 06:10

MByD


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.

like image 35
Pavul Avatar answered Oct 06 '22 07:10

Pavul