Just after creating the new Android Application Project I get the error "R cannot be resolved to a variable" in my MainActivity.java file.
This is it's content:
package com.example.firstapp;
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.activity_main, menu);
return true;
}
}
Why am I getting this problem if the app was created by Eclipse choosing all the default options? How can I fix this issue?
It might be because, there might be some problem in your res folder,
The Main reason might be there could be wrong import file of R.java
. So Remove, if any import android.R;
There might be some images with same name, or some files with capital letters, or even there might be some errors in your xml files,
Try rebuilding and cleaning your project.
For some quick solutions to this problem, have a look at this,
R.java file not getting created
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With