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

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

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

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

Q&A

0回答

1236閲覧

java.lang.IllegalStateException: <テキストビュー> must not be nullエラーの原因が不明

yukari00

総合スコア5

Kotlin

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

0グッド

0クリップ

投稿2020/06/26 14:31

編集2020/06/27 01:47

こんにちは。エラーに関しての質問です。
java.lang.IllegalStateException: text_tell_which_team must not be null
と出ました。
調べたところ、このエラーは間違ったIdを使ったり、別のレイアウトを呼び出しているときに出てくるみたいなのですが、、ここにそのような間違いはありません。

そしてこれは常に起こるのではなく、以下の条件で起きます。
①ルームを作成し、WaitingMembersFragment→GameSettingFragmentに遷移するとき。(ルーム参加してGameSettingFragに遷移した場合はこのようなエラーコードは出ず、正常に処理されます)

ここに全てのコードを載せることができないので、一旦エラーが出たところのメソッドとレイアウトを載せます。
他はGithubに載せているのでご参照ください。
GitHub

<追記>
ログを使って調べたところ、多くのテキストビューがnullになっていることがわかり、(全てのテキストビューを調べたわけではないので多くのと書きました)activityもnullになっていたので、もしかしたら何かしらの理由で、普通はフラグメントが開く前に通るところを通っていないんだと思います。

↑さらに追記です。
ログを使ってさらに調べたところ、
FirebaseのaddSnapshotListener(リアルタイムでデータ取得するメソッド)を出力した後に、テキストビューがnullになっているということが判明しました。ますます意味がわかりません。なぜ、途中でテキストビューがnullになってしまうのでしょう??

private fun getTwoTeamInfoFromFirestore() { Log.d("text1", "$text_tell_which_team")//これはnullではない listeningMembers = database.collection(dbCollection).document(keyword).collection("members") .addSnapshotListener { it, e -> val membersListUpdate: MutableList<Uid> = mutableListOf() val teamRed: MutableList<Uid> = mutableListOf() val teamBlue: MutableList<Uid> = mutableListOf() Log.d("!!!!!!!!!!!!", "!!!!!!!!!!!!!!") if(e != null) return@addSnapshotListener if(it == null || it.isEmpty) return@addSnapshotListener for (document in it) { val name = document.getString("name")?: "" val uid = document.id val team = document.getString("team") membersListUpdate.add(Uid(name, uid)) if(team == "RED") teamRed.add(Uid(name, uid)) else teamBlue.add(Uid(name, uid)) } Log.d("text2", "$text_tell_which_team")//null membersList = membersListUpdate if(teamRed.size != 0) { setSpinner(teamRed, teamBlue) individualsInfo(teamRed, teamBlue) } } }
override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_game_setting, container, false) }
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.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" android:background="@drawable/shape_round_corners" tools:context=".GameSettingFragment"> <TextView android:id="@+id/text_tell_which_team" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="あなたは赤チームです" android:textColor="@color/WHITE" android:gravity="center" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/text_blue_mem_num" /> <TextView android:id="@+id/text_if_leader" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:text="あなたはスパイマスターです" android:textColor="@color/WHITE" android:gravity="center" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/text_tell_which_team" /> <LinearLayout android:id="@+id/linear" android:layout_width="match_parent" android:layout_height="0dp" android:layout_marginStart="16dp" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:orientation="vertical" app:layout_constraintBottom_toTopOf="@+id/linearLayout" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/text_if_leader" app:layout_constraintVertical_bias="0.0"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="あなたの仲間は..." android:textColor="@color/WHITE" android:gravity="center"/> <TextView android:id="@+id/text_my_team_members" android:layout_width="match_parent" android:layout_height="match_parent" android:textColor="@color/WHITE" android:gravity="center"/> </LinearLayout> <LinearLayout android:id="@+id/linearLayout" android:layout_width="400dp" android:layout_height="wrap_content" android:layout_margin="16dp" android:orientation="horizontal" app:layout_constraintBottom_toTopOf="@+id/liner_btn" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/linear" > <TextView android:id="@+id/textView2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="4" android:gravity="center" android:text="スパイマスターを変更しますか" android:textColor="@color/WHITE"/> <Spinner android:id="@+id/spinner" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" /> <Button android:id="@+id/btn_change_leader" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/ic_baseline_cached_24"/> </LinearLayout> <Button android:id="@+id/btn_leave_room" android:layout_width="30dp" android:layout_height="30dp" android:layout_margin="12dp" android:background="@drawable/ic_baseline_arrow_back_24" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent"/> <LinearLayout android:id="@+id/liner_btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_margin="12dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent"> <Button android:id="@+id/btn_team_random" android:layout_width="0dp" android:layout_height="30dp" android:layout_marginEnd="6dp" android:layout_weight="1" android:background="@drawable/shape_round_coners_winered" android:text="ランダム" android:textColor="@color/WHITE" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" /> <Button android:id="@+id/btn_prepared" android:layout_width="0dp" android:layout_height="30dp" android:layout_weight="1" android:layout_marginStart="6dp" android:background="@drawable/shape_round_coners_winered" android:text="準備完了" android:textColor="@color/WHITE" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" /> </LinearLayout> <TextView android:id="@+id/text_red_mem_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:layout_marginEnd="16dp" android:text="赤チーム人数" android:textColor="@color/WHITE" android:textSize="12dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> <TextView android:id="@+id/text_blue_mem_num" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginEnd="16dp" android:text="青チーム人数" android:textColor="@color/WHITE" android:textSize="12dp" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/text_red_mem_num" /> </androidx.constraintlayout.widget.ConstraintLayout>

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

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

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

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

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

yukari00

2020/06/28 11:09

了解したしました!本当にありがとうございます!!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問