###前提・実現したいこと
ソーテック社発行のこれ一冊できるAndroidStudioアプリ開発入門の手順に沿ってじゃんけんゲームを作っています。
###発生している問題・エラーメッセージ
おそらくonClickで結びつけたメソッドがうまく動かずラジオボタンの選択までは動きますがその後の処理で落ちます。
エミュレータ上でmyfirstapp has stoppedと表示されアプリが落ちてしまいます。
###該当のソースコード
[MainActivity.java] package com.example.kazu.myfirstapp; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.RadioButton; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private RadioButton radioGoo; private RadioButton radioChoki; private RadioButton radioPaa; private TextView resultTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); radioGoo = (RadioButton)findViewById(R.id.radioGoo); radioChoki = (RadioButton)findViewById(R.id.radioChoki); radioPaa = (RadioButton)findViewById(R.id.radioPaa); } public void onDuel(View view){ Toast.makeText(this,"私はグー",Toast.LENGTH_SHORT).show(); String resultString = "残念でした"; if(radioGoo.isChecked()){ resultString = "引き分けです"; }else if(radioPaa.isChecked()){ resultString = "おめでとう"; } resultTextView.setText(resultString); } } [activity_main.xml] <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.kazu.myfirstapp.MainActivity"> <TextView android:id="@+id/titleTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_alignParentTop="true" android:layout_marginStart="18dp" android:layout_marginTop="14dp" android:text="@string/title_janken" android:textAppearance="@android:style/TextAppearance.Material.Large" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintHorizontal_bias="0.068" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.027" /> <Button android:id="@+id/showResultButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:onClick="onDuel" android:text="@string/button_showsign" android:textSize="22sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.499" /> <RadioGroup android:id="@+id/gooChokiPaaGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/resultTextView" android:layout_alignParentEnd="true" android:layout_alignParentStart="true" android:layout_marginBottom="80dp" android:orientation="horizontal"> <RadioButton android:id="@+id/radioGoo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/goo" /> <RadioButton android:id="@+id/radioChoki" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/choki" /> <RadioButton android:id="@+id/radioPaa" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/paa" /> </RadioGroup> <TextView android:id="@+id/resultTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/showResultButton" android:layout_centerHorizontal="true" android:layout_marginBottom="40dp" android:text="@string/start_janken" /> </RelativeLayout>
###試したこと
onDuelの内容をトーストのみにした場合、アプリは落ちませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。