i am a new android developer stucked in this error, I've read other threads, following the instructions but there is no way to solve it. This is the file res/layout/activity_main.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="300dp"
android:layout_height="225dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textSize="30sp"
android:textColor="#613def"
android:textStyle="bold"
android:background="@drawable/microphonegrey"/>
</RelativeLayout>
in the class MainActivity.java:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
with the Error "activity_main cannot be resolved or is not a field"
I choose Create field 'activity_main' in type 'menu'
The field is created, but then I see this message in the console:
[2014-07-27 23:11:30 - TestProject] R.java was modified manually! Reverting to generated version!
over and over again..., cleaning the project, saving...With the same result, the import clause is the correct in the file:
import mypackage.R, not android.R
If it is in your res/layout folder your code should look like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
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.
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.