1
ボタンがNULLの理由は何ですか?Android Nullボタン
Button press;
//...
press = (Button) findViewById (R.id.enter);
if (press != null)
press.setOnClickListener(this);
私はマニフェスト、xmlファイル、コードをチェックし...私は私が紹介した後、それはすべてが起こった...まだボタンがNULLで、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
はい私はそれを設定しました – Madrugada
あなたのoncreateとレイアウトのXMLを提出して – Rotemmiz