1
按鈕爲NULL的原因可能是什麼?Android Null按鈕
Button press;
//...
press = (Button) findViewById (R.id.enter);
if (press != null)
press.setOnClickListener(this);
我檢查清單,XML文件,代碼...我沒有R.id.enter的任何重複,還是按鈕是空......這一切發生後,我公司推出了新的活動......
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
press = (Button) findViewById (R.id.enter);
if (press != null)
press.setOnClickListener(this);
}
這裏的XML(main.xml中):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/gift2"
>
<Button
android:id="@+id/enter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="415dp"
android:background="@drawable/pattern"
android:layout_gravity="center_horizontal"
android:text="Open your box now!"
android:textSize="20sp"
/>
</LinearLayout>
您是否使用佈局設置了內容視圖? – Rotemmiz 2012-02-11 20:55:23
是的,我確實設置了它 – Madrugada 2012-02-11 20:57:59
提交您的oncreate和佈局xml – Rotemmiz 2012-02-11 20:58:44