0
何らかの理由でrunメソッドがコンテンツビューを設定するのに問題はありませんが、xmlからボタンを取得しようとするとnullが返され、 onclickリスナー。私のコードは以下の通りです。findViewByIdは実行メソッド(アンドロイド)内でヌルを返しています
v.post(new Runnable() {
@Override
public void run() {
setContentView(R.layout.win);
Button submit = (Button) findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
HighScoresHelper scores = new HighScoresHelper("HighScoreV2.txt", GameActivity.this);
scores.addScore("Test", Math.round((frame/FPS) *100)/100.0);
startActivity(new Intent(GameActivity.this, HighScores.class));
finish();
}
});
}
});
、はい、スペルとすべてがすべて正しいとxmlでアップ一致し、ここで
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="YOU WON!!!, enter in your name and click submit"
android:id="@+id/textView3" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/name" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:id="@+id/submit"
android:layout_gravity="center_horizontal" />
</LinearLayout>
が
あなたのアプリケーションや 'android'名前空間からの' R'ですか? – Eun
@Eunアンドロイドの名前空間だったらコンパイルできません。 'id.submit'と' layout.win'はその名前空間の下に存在しません。 – njzk2
xmlは 'layout/win.xml'の内容とまったく同じですか?あなたのプロジェクトをきれいにして再建しようとしましたか? – njzk2