简体   繁体   中英

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);
    }

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.

Also, start accepting some answers. I almost didn't answer this because of your horrible acceptance rate.

Try to import the R.java file with the full path inside the main activity class file...

import com.example.packagename.R;

Hope, this will solve your query.

This may be a very simple answer, but it has happened to me before. Try to restart eclipse. File -> Restart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM