我刚刚开始构建 Android 应用程序。还有这个错误
button cannot be resolved to a type
总是让我烦恼。这是java代码
package com.android.revision1;
import android.app.Activity;
import android.os.Bundle;
public class Revision1Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button=(Button) findViewByid(R.layout.button1);
}
}
这是Xml代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button" />
</LinearLayout>
最佳答案
button
似乎未声明,因此声明该字段
private Button button;
或局部变量:
Button button=(Button) findViewByid(R.layout.button1);
关于java - 类型无法解析或不是字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33660898/