javaandroidprogram-entry-point

Main layout not recognized, immediately after starting new Android project


The below code was automatically generated when I started a new android project.

I'm getting an error on the "R.layout.main" saying it does not exist.

I do in fact have a main.xml and I can see the layout change as I edit it in the Graphical Layout tab.

How can I fix this so I can run my application?

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

Solution

  • The package name of the R file and the package name of your source code may not match. Make sure the package your code is in is the same as the package defined in the manifest file. Otherwise you will need to import the R file with the full package name (ex: com.example.R.layout.main).

    If they match, for some reason your R file was not generated properly. Try cleaning your project.