[英]activity_main cannot be resolved or is not a field
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. 我是一个陷入此错误的新的android开发人员,我已经按照说明阅读了其他线程,但是没有办法解决。 This is the file res/layout/activity_main.xml:
这是文件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: 在类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" 错误“ activity_main无法解析或不是字段”
I choose Create field 'activity_main' in type 'menu' 我在类型“菜单”中选择创建字段“ activity_main”
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子句在文件中是正确的:
import mypackage.R, not android.R
If it is in your res/layout folder your code should look like this: 如果位于res / layout文件夹中,则代码应如下所示:
@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;
在
imports import android.R;
从代码中删除imports import android.R;
or import your.application.packagename.R;
或
import your.application.packagename.R;
Now clean the project and run it. 现在清理项目并运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.