###前提・実現したいこと
アンドロイドアプリの画面遷移
###発生している問題・エラーメッセージ
画面遷移時に強制終了が起きてしまいます。
色々なサイトをみてAndroidManifestを追記したりコードを書き直したりしているのですが上手くいきません。
どなたかお力添えいただけないでしょうか?よろしくお願いいたします。
追記
logcatのエラーの先頭には下記の様に出力されていました。
18274-18274/jp.hashimoto.hashimoto.randamsumabura E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{jp.hashimoto.hashimoto.randamsumabura/jp.hashimoto.hashimoto.randamsumabura.CharaSlotActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
###該当のソースコード
MainActivity.java
package jp.hashimoto.hashimoto.randamsumabura; //インポートは省略 public class MainActivity extends Activity { //変数の宣言 private LoopEngine loopEngine = new LoopEngine();//ハンドラ用 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final Button btn = (Button) findViewById(R.id.Change_button); final Button charabtn=(Button) findViewById(R.id.button_chara_battle);//画面遷移ボタン btn.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if(loopEngine.isUpdate==false) { loopEngine.start(); btn.setText("STOP!"); } else if(loopEngine.isUpdate==true) { loopEngine.stop(); btn.setText("SELECT"); } } }); //画面遷移ボタン charabtn.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { Chara_button_OnClickListener(v); }}); } public void Chara_button_OnClickListener(View v) { //SubActivityを起動します。 Intent intent = new Intent(this,jp.hashimoto.hashimoto.randamsumabura.CharaSlotActivity.class); startActivityForResult(intent,0); }
上記のMainActivityから下記のCharaSlotActivity(サブアクテビティ)に遷移したい
CharaSlotActivity.java
package jp.hashimoto.hashimoto.randamsumabura; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class CharaSlotActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activitycharaslot); final Button btn = (Button) findViewById(R.id.button_CF_mi); } }
###試したこと
AndroidManifestに下記の様に追記しました。
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jp.hashimoto.hashimoto.randamsumabura" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/> <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".CharaSlotActivity"></activity>//遷移先の登録(追記箇所)
デバッグをしたところ、遷移先のCharaSlotActivity.javaの下記のコードをステップオーバーした直後にアプリが落ちている感じでした。多くのボタンやテキストをレイアウトに置いているのでそのせいで落ちた可能性もあるのでしょうか?
setContentView(R.layout.activitycharaslot);
追記:
起動したときに最初に表示される画面を遷移先のレイアウトにしたところ同様に強制終了が起きましたのでlayoutに問題がありそうなのですがレイアウトファイルをみてもわたしの力ではエラーを発見することが出来ませんでしたので遷移先のレイアウトファイルを載せさせていただきます。非常に長いコードで申し訳ありません。文字数制限にひっかかってしまいますのでアップローダーに上げさせていただきました。activitycharaslot.xml
###補足情報(言語/FW/ツール等のバージョンなど)
言語 Androidjava
環境 AndroidStudio 2.3
デバッグ環境 実機Nexus5(Android 6.0)
回答4件
あなたの回答
tips
プレビュー