LoginSignup
0
0

More than 3 years have passed since last update.

[Android] Chip使用時にInvocationTargetExceptionが発生する

Last updated at Posted at 2019-11-01

概要

 Androidアプリ開発時にChipを利用しようとしたら、InvocationTargetExceptionが発生。私が解決した方法を記述します。

※注意 私が解決できた方法であり、必ず解決するわけではないと思うので、「もしかしたら解決するかも?」程度にお試しください...

解決方法

android:textAppearanceを設定したらエラーを解消できました。
xml

xml.fragment.xml
<com.google.android.material.chip.ChipGroup
            android:id="@+id/chooseService_chipGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <com.google.android.material.chip.Chip
                android:id="@+id/chip1"
                style="@style/Widget.MaterialComponents.Chip.Filter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"/>

            <com.google.android.material.chip.Chip
                android:id="@+id/chip2"
                style="@style/Widget.MaterialComponents.Chip.Filter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"/>

            <com.google.android.material.chip.Chip
                android:id="@+id/chip3"
                style="@style/Widget.MaterialComponents.Chip.Filter"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceMedium"/>
</com.google.android.material.chip.ChipGroup>

まとめ

 今回はxml上で静的にTextAppearanceを設定しましたが、動的に行う場合はChip.setTextAppearanceで行うことができます。
 InvocationTargetExceptionはコンストラクタなどで発生する例外なので、xmlの要素に設定した値が間違っているか、不足している場合に呼び出されます。そのため、もう一度設定した値が間違っていないかを確かめてみてください。

参考文献

AndroidDevelopers Chip
https://developer.android.com/reference/com/google/android/material/chip/Chip

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0