我是Android編程的新手。我有一個程序,看起來像這樣:main.xml中的訪問變量
這裏是主要的Java模塊:
public class MyAndroid extends Activity {
private EditText input1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.main);
input1 = (EditText) findViewById(R.id.input1);
}
這是我的main.xml文件看起來像:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout android:id="@+id/widget45"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<EditText android:id="@+id/input1" android:layout_width="160px"
android:layout_height="wrap_content" android:textSize="18sp"
android:numeric = "decimal|signed"
android:layout_x="8px" android:layout_y="13px">
</EditText>
</AbsoluteLayout>
不過,我收到錯誤信息:
R.id.input1無法解析。爲什麼我無法從main.xml訪問'input1'?
我環顧四周,並沒有找到答案。
感謝
請正確格式化代碼,但選擇它並按下CTRL + K。 – EboMike 2010-10-28 22:59:50
至於你的問題 - 它*應該*工作。你看到R.Java中的input1嗎? – EboMike 2010-10-28 23:00:47
你的代碼看起來沒問題。如果您使用的是Eclipse,是否嘗試「清理」該項目,重新構建它,或者甚至在沒有其他操作的情況下重新啓動Eclipse。 – 2010-10-28 23:02:13