简体   繁体   中英

R.java missing in unmodified android application project

I did a lot of research before asking this question and I don't think that I have a typical "R.java is missing" problem.

I downloaded the Eclipse platform, installed the android plug-ins from developer.android.com, and opened a new Android Application Project.

Empty projects default with a simple "Hello World" program and I simply wanted to test if this was working before I continued. The code wouldn't compile and the error message was "R cannot be resolved to a variable". It turned out that the R.java file didn't exist.

I've tried everything to get it to generate the file:

  1. Rebuilding the project
  2. Restarting Eclipse
  3. Project > Clean
  4. Deleting the gen folder and recreating it
  5. Making a different project and trying to compile it
  6. Checking for updates
  7. Copying the R.java file from another project (which I made on a different computer)
  8. I even downloaded Eclipse again from another website.

So far nothing has worked.

Any ideas?

package com.example.pleasework;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}

Make sure you are using the Android SDK to do your Android development. You can get it here: http://developer.android.com/sdk/index.html

This contains the version of Eclipse you need, with all the plug-ins you need.

You can use Ctrl + Shift + O command to "Organize Imports" and generate any missing import statements

Sometimes this would generate the incorrect import statement which would hide the R.java

for more information look http://source.android.com/source/using-eclipse.html

and R cannot be resolved - Android error

Maybe check your XML files? One single error can ruin your whole project. But then again, I've been using Android Studio since the release and I'm maybe messing things up here.

You say you have installed adt. But what about setting the android folder in eclipse in Window -> Preferences ->Android. Now if the gen folder is created you can add

import com.example.pleasework.R;

to make it work.

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