I am a beginner in android and I was trying to make a simple application on android and this "activity_main" error is not getting cleared.I have gone through all the available answers
import android.R;
import android.app.Activity;
import android.os.Bundle;
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;
}
}
Clean project then try to run it. I faced the same problem. You can also do this:
Remove from your code following imports import android.R;
or import your.application.packagename.R;
Now clean the project and run it.
Let me explain(put more detail) what exactly is happening with the above code.
FYI, there are two types of R.java
file exists:
R.java
file, which you would use to access resources/layout of your project.R.java
file which contains ID/index of the native resources like anim, color and many more resources, which you can access by using android.R.color.black
way.Now, you are making mistake by importing android.R
which is not allowing you to access main_activity.xml
of your project.
Remove android.R
and import R file of your project. You can press CTRL + SHIFT + O simply, will display available options.
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