質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

Q&A

解決済

1回答

4740閲覧

Android Studio Kotlin 同じ画面から3つ別々の画面へ遷移

siren

総合スコア10

Android

Androidは、Google社が開発したスマートフォンやタブレットなど携帯端末向けのプラットフォームです。 カーネル・ミドルウェア・ユーザーインターフェイス・ウェブブラウザ・電話帳などのアプリケーションやソフトウェアをひとつにまとめて構成。 カーネル・ライブラリ・ランタイムはほとんどがC言語/C++、アプリケーションなどはJavaSEのサブセットとAndroid環境で書かれています。

Android Studio

Android Studioは、 Google社によって開発された、 Androidのネイティブアプリケーション開発に特化した統合開発ツールです。

Kotlin

Kotlinは、ジェットブレインズ社のアンドリー・ブレスラフ、ドミトリー・ジェメロフが開発した、 静的型付けのオブジェクト指向プログラミング言語です。

0グッド

0クリップ

投稿2018/09/17 09:37

編集2018/09/17 13:47

すみません先人の皆様、知恵をお貸しください。

発生している問題・エラーメッセージ

以下のコードでコンパイルしてみたのですが、
画面遷移せずに強制終了してしまいます。
どうしたらそれぞれのボタンで別のActivityへ出来ますでしょうか?

こちらMainActivity.ktです。

class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //キャラクターボタン押したときの処理を後述 val charactor0101Button = findViewById<Button>(charactor) charactor0101Button.setOnClickListener { val intent = Intent(this,charactor0101::class.java) startActivity(intent) } //クリーチャーボタンを押したときの処理 val creature0101Button = findViewById<Button>(creature) creature0101Button.setOnClickListener { val intent = Intent(this, creature0101::class.java) startActivity(intent) } //セッティングボタンを押したときの処理 val setting0101Button = findViewById<Button>(setting) setting0101Button.setOnClickListener { val intent = Intent(this,setting0101::class.java) startActivity(intent) } }

こちらactivity_main.xmlです。

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout 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=".MainActivity"> <LinearLayout android:id="@+id/linearLayout" android:layout_width="368dp" android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginStart="8dp" android:gravity="bottom" android:orientation="horizontal" android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"> <Button android:id="@+id/charactor" style="@style/Widget.AppCompat.Button" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_weight="1" android:text="@string/charactor" /> <Button android:id="@+id/creature" style="@style/Widget.AppCompat.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/creature" /> <Button android:id="@+id/setting" style="@style/Widget.AppCompat.Button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/setting" /> </LinearLayout> <android.support.constraint.Guideline android:id="@+id/guideline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" app:layout_constraintGuide_begin="232dp" /> </android.support.constraint.ConstraintLayout>

試したこと

どれか1行のみであれば起動することは確認しております。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2018/09/17 12:25

画面遷移時に強制終了したときのエラーを記述してください。
退会済みユーザー

退会済みユーザー

2018/09/17 12:26

activity_main.xml の中身もお願いします。
退会済みユーザー

退会済みユーザー

2018/09/17 12:27

それから、findViewById()の引数にある変数の中身もお願いします
siren

2018/09/17 13:41

すみません今改めてコンパイルしようとしたのですが、Unresolved referenceということでcreature0101とsetting0101にエラーが出ました。
siren

2018/09/17 13:42

コンパイルはこの配置だとうまくいかないみたいで、成功したというのは勘違いみたいです。
退会済みユーザー

退会済みユーザー

2018/09/17 13:46

そのcreature0101とsetting0101というのは存在しますか?(先頭小文字ですけど・・・これはクラスですか?変数ですか?)
退会済みユーザー

退会済みユーザー

2018/09/17 13:47

Unresolved referenceとだけ書かれても原因が突き止められないので、Unresolved referenceと書かれている部分を全文ください。
退会済みユーザー

退会済みユーザー

2018/09/17 13:49

それからもう一度になりますが、 findViewById<Button>()に渡されている変数(charactor、creature、setting)には何が入っていますか?
siren

2018/09/17 13:56

こちらクラス名だったのですが、再度確認したところ私の打ち間違いで大文字と小文字の区別がついていなかっただけのようです。すみません本当にありがとうございました。
退会済みユーザー

退会済みユーザー

2018/09/17 13:57

分かりました。ご自身で解決したのであれば、回答入れて解決済みにしちゃってください。
siren

2018/09/17 14:01

分かりました。
guest

回答1

0

自己解決

原因はクラス名の大文字小文字を間違えていただけでした(-_-;)
お騒がせ致しました。

投稿2018/09/17 14:03

siren

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問