简体   繁体   中英

Why is my main.xml invisible to the compiler?

I do have a \\res\\layout\\main.xml file.

Yet, this:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

...gives me the err msg, "R cannot be resolved to a variable"

in my Activity.java file.

What am I missing?

Alright, I see there is nothing in the project's Gen folder. What would cause it to not get populated?

Here are the steps which helps me to resolve this problem.

  1. Delete R.java (Eclipse will recreate it immediately. If not there is a problem with the code or layout)
  2. Clean the project (Eclipse menu 'Project' & 'Clean'
  3. Recompile the project

These steps resolve the problem with my work.

1) Make sure there is nothing wrong in your Manifest file.

2) In eclipse, click project -> clean

3) If that didn't work, you still have something wrong in your manifest file. Rinse and repeat.

First Check your R.java file is generated or not. if not clean and build your project even though file is not created then try to remove your last added xml file in layout. since If there is any error or problem in adding xml file R.java will not generated. Check your manifest file too.

清理您的项目并重建APK

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