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

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

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

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

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

Android Studio

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

Q&A

0回答

2501閲覧

エラーメッセージ:Error inflating class ImageViewについて(AndroidStudio)

tanaka_hana

総合スコア19

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Android

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

Android Studio

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

0グッド

0クリップ

投稿2018/12/16 07:41

編集2018/12/16 09:09

前提・実現したいこと

リストビューで一覧を作り、チェックマークとしてタップしたリストの行には画像を表示させる(他の行をタップすると先のタップした行の画像は消える)という機能をつけたいです。自分でAdapaterを定義して、選択中のアイテムの状態を保持、選択状態の切り替えができるようにしました。
また、ImageViewの画像を選択状態により切り替わるようにdrawableリソースのselectorを使用しています。

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

以下のエラーメッセージが表示されて、アプリ自体が起動しません。

android.view.InflateException: Binary XML file line #9: Binary XML file line #9: Error inflating class ImageView Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class ImageView Caused by: android.content.res.Resources$NotFoundException: Drawable com.websarva.wings.android.アプリ名:drawable/checkselector with resource ID #0x7f060062 Caused by: android.content.res.Resources$NotFoundException: File res/drawable/checkselector.xml from drawable resource ID #0x7f060062

該当のソースコード

アプリ自体のソースコードを記述します。
javaフォルダ内

java

1public class ConditionSelectActivity extends AppCompatActivity { 2 3 private String airport; 4 private List<Map<String,String>> TimeZoneList; 5 private static final String[] FROM={"minTime","maxTime"}; 6 private static final int[] TO={R.id.tvMinTime,R.id.tvMaxTime}; 7 private SingleSelectAdapter adapter; 8 9 @Override 10 protected void onCreate(Bundle savedInstanceState) { 11 super.onCreate(savedInstanceState); 12 setContentView(R.layout.activity_condition_select); 13 14 Intent intent=getIntent(); 15 airport=intent.getStringExtra("airport"); 16 17 //TimeZone(リスト画面上側)を表示させる 18 ListView lvTimeZone=findViewById(R.id.lvTimeZone); 19 TimeZoneList=createTimeZoneList(); 20 adapter=new SingleSelectAdapter(ConditionSelectActivity.this,TimeZoneList,R.layout.timezone_list,FROM,TO); 21 lvTimeZone.setAdapter(adapter); 22 23 //TimeZoneリストをタップした時の処理 24 lvTimeZone.setOnItemClickListener(new ListTimeZoneClickListener()); 25 } 26 27 private List<Map<String,String>> createTimeZoneList(){ 28 29 List<Map<String,String>> timeZoneList=new ArrayList<>(); 30 //HashMapでMaxTime〜MinTimeを作成 31 Map<String,String> timeZone=new HashMap<>(); 32 timeZone.put("minTime","12:00"); 33 timeZone.put("maxTime","12:30"); 34 timeZone.put("check","no"); 35 timeZoneList.add(timeZone); 36 37 timeZone=new HashMap<>(); 38 timeZone.put("minTime","12:31"); 39 timeZone.put("maxTime","13:00"); 40 timeZone.put("check","no"); 41 timeZoneList.add(timeZone); 42 43 timeZone=new HashMap<>(); 44 timeZone.put("minTime","13:01"); 45 timeZone.put("maxTime","13:30"); 46 timeZone.put("check","no"); 47 timeZoneList.add(timeZone); 48 49 //ArrayList(MaxTime.MinTime)を返す 50 return timeZoneList; 51 } 52 53 //TimeZoneListがタップされた時の処理が記述されたメンバクラス 54 private class ListTimeZoneClickListener implements AdapterView.OnItemClickListener{ 55 56 @Override 57 public void onItemClick(AdapterView<?> parent, View view,int position,long id){ 58 59 Map<String,String> timeZone=(Map<String, String>) parent.getItemAtPosition(position); 60 adapter.toggleSelection(position); 61 62 } 63 } 64 65}

以下は自分で定義したSingleAdapterです

java

1public class SingleSelectAdapter extends SimpleAdapter { 2 3 LayoutInflater mInflater; 4 private int selectedIndex = -1; // 初期値は選択なし 5 6 7 8 // コンストラクタ 9 public SingleSelectAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] FROM, int[] TO){ 10 super(context, data, resource, FROM, TO); 11 } 12 13 // 指定した位置の選択状態を切り替えるメソッド 14 public void toggleSelection(int position) { 15 if (position == selectedIndex) { 16 selectedIndex = -1; 17 } else { 18 selectedIndex = position; 19 } 20 notifyDataSetChanged(); // リストの更新を促す 21 } 22 23 @Override 24 public View getView(int position, View convertView, ViewGroup parent) { 25 View view = super.getView(position, convertView, parent); 26 // 選択された位置であればviewを選択状態にする 27 view.setSelected(position == selectedIndex); 28 return view; 29 } 30 31}

layoutフォルダ内のxmlです

xml

1<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:app="http://schemas.android.com/apk/res-auto" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:id="@+id/topconstaraint"> 7 8 <ImageView 9 android:id="@+id/ivcheck" 10 android:layout_width="55dp" 11 android:layout_height="38dp" 12 android:layout_marginStart="8dp" 13 android:layout_marginTop="8dp" 14 android:src="@drawable/checkselector" 15 app:layout_constraintBottom_toTopOf="@+id/guideline2" 16 app:layout_constraintStart_toStartOf="parent" 17 app:layout_constraintTop_toTopOf="@+id/guideline2" /> 18 19 <android.support.constraint.ConstraintLayout 20 android:layout_width="0dp" 21 android:layout_height="match_parent" 22 app:layout_constraintEnd_toEndOf="parent" 23 app:layout_constraintStart_toEndOf="@+id/ivcheck"> 24 25 <TextView 26 android:id="@+id/tvMinTime" 27 android:layout_width="wrap_content" 28 android:layout_height="38dp" 29 android:layout_marginStart="8dp" 30 android:layout_marginTop="8dp" 31 android:layout_marginBottom="8dp" 32 android:textSize="20sp" 33 app:layout_constraintBottom_toTopOf="@+id/guideline" 34 app:layout_constraintStart_toStartOf="parent" 35 app:layout_constraintTop_toTopOf="@+id/guideline" /> 36 37 <TextView 38 android:id="@+id/textView2" 39 android:layout_width="wrap_content" 40 android:layout_height="38dp" 41 android:layout_marginStart="8dp" 42 android:layout_marginTop="8dp" 43 android:layout_marginBottom="8dp" 44 android:text="@string/timezone_linear" 45 android:textSize="20sp" 46 app:layout_constraintBottom_toTopOf="@+id/guideline" 47 app:layout_constraintStart_toEndOf="@+id/tvMinTime" 48 app:layout_constraintTop_toTopOf="@+id/guideline" /> 49 50 <TextView 51 android:id="@+id/tvMaxTime" 52 android:layout_width="wrap_content" 53 android:layout_height="38dp" 54 android:layout_marginStart="8dp" 55 android:layout_marginTop="8dp" 56 android:layout_marginBottom="8dp" 57 android:textSize="20sp" 58 app:layout_constraintBottom_toTopOf="@+id/guideline" 59 app:layout_constraintStart_toEndOf="@+id/textView2" 60 app:layout_constraintTop_toTopOf="@+id/guideline" /> 61 62 <android.support.constraint.Guideline 63 android:id="@+id/guideline" 64 android:layout_width="wrap_content" 65 android:layout_height="wrap_content" 66 android:orientation="horizontal" 67 app:layout_constraintGuide_begin="35dp" /> 68 69 </android.support.constraint.ConstraintLayout> 70 71 <android.support.constraint.Guideline 72 android:id="@+id/guideline2" 73 android:layout_width="wrap_content" 74 android:layout_height="wrap_content" 75 android:orientation="horizontal" 76 app:layout_constraintGuide_begin="27dp" /> 77 78</android.support.constraint.ConstraintLayout>

drawableリソースです

xml

1<?xml version="1.0" encoding="UTF-8"?> 2<selector xmlns:android="http://schemas.android.com/apk/res/android"> 3 <item 4 android:state_selected="true" 5 android:drawable="@drawable/check" /> 6 <item android:drawable="@null" /> 7</selector>

試したこと

APIレベル24以上でないと表示されない画像を格納するフォルダに入れていたのが原因ではないかと思ったのですが、drawable−24のフォルダ内に入れているのかと思い、確認したところきちんと使用したい画像はdrawableフォルダに入っていました。

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

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

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

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

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

退会済みユーザー

退会済みユーザー

2018/12/16 13:54

一度cleanしたり、キャッシュを消して再起動すると直ることがありますが・・・どうでしょう?
tanaka_hana

2018/12/16 20:49

返信ありがとうございます。。試して見たものの同様のエラーメーッセージがでて、アプリ自体が起動できません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

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

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

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問