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

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

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

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

Q&A

解決済

1回答

1919閲覧

Android Studio 実機でのテストのエラーについて

uhsi

総合スコア57

Android Studio

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

0グッド

1クリップ

投稿2019/05/26 10:39

編集2019/05/30 07:29

ImageViewを使用した場合のみ実機でのテストの際に「問題が発生しました」とデバイスに表示されてプログラムを開くことができません。
エミュレーターを使用した場合はエラーが発生しません。

http://hakoniwadesign.com/?p=10873
こちらの情報を参考にさせていただきました。

LogCat

105-29 16:39:01.993 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$OnUnhandledKeyEventListenerWrapper', referenced from method android.support.v4.view.ViewCompat.addOnUnhandledKeyEventListener 205-29 16:39:01.995 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.dispatchApplyWindowInsets 305-29 16:39:02.009 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.view.WindowInsets', referenced from method android.support.v4.view.ViewCompat.onApplyWindowInsets 405-29 16:39:02.010 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.view.View$OnUnhandledKeyEventListener', referenced from method android.support.v4.view.ViewCompat.removeOnUnhandledKeyEventListener 505-29 16:39:02.017 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.support.v4.view.ViewCompat$1', referenced from method android.support.v4.view.ViewCompat.setOnApplyWindowInsetsListener 605-29 16:39:02.035 2177-2177/com.example.myegg E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering 705-29 16:39:02.060 2177-2177/com.example.myegg E/AndroidRuntime: FATAL EXCEPTION: main 8 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myegg/com.example.myegg.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class ImageView 9 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2234) 10 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2287) 11 at android.app.ActivityThread.access$600(ActivityThread.java:183) 12 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1288) 13 at android.os.Handler.dispatchMessage(Handler.java:99) 14 at android.os.Looper.loop(Looper.java:137) 15 at android.app.ActivityThread.main(ActivityThread.java:5252) 16 at java.lang.reflect.Method.invokeNative(Native Method) 17 at java.lang.reflect.Method.invoke(Method.java:511) 18 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798) 19 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565) 20 at dalvik.system.NativeStart.main(Native Method) 21 Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class ImageView 22 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 23 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 24 at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 25 at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 26 at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 27 at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 28 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 29 at com.example.myegg.MainActivity.onCreate(MainActivity.java:19) 30 at android.app.Activity.performCreate(Activity.java:5146) 31 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092) 32 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198) 33 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2287)  34 at android.app.ActivityThread.access$600(ActivityThread.java:183)  35 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1288)  36 at android.os.Handler.dispatchMessage(Handler.java:99)  37 at android.os.Looper.loop(Looper.java:137)  38 at android.app.ActivityThread.main(ActivityThread.java:5252)  39 at java.lang.reflect.Method.invokeNative(Native Method)  40 at java.lang.reflect.Method.invoke(Method.java:511)  41 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)  42 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)  43 at dalvik.system.NativeStart.main(Native Method)  44 Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f060055 a=-1 r=0x7f060055} 45 at android.content.res.Resources.loadDrawable(Resources.java:1927) 46 at android.content.res.TypedArray.getDrawable(TypedArray.java:601) 47 at android.widget.ImageView.<init>(ImageView.java:120) 48 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:72) 49 at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68) 50 at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182) 51 at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106) 52 at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266) 53 at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316) 54 at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675) 55 at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)  56 at android.view.LayoutInflater.inflate(LayoutInflater.java:489)  57 at android.view.LayoutInflater.inflate(LayoutInflater.java:396)  58 at android.view.LayoutInflater.inflate(LayoutInflater.java:352)  59 at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)  60 at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)  61 at com.example.myegg.MainActivity.onCreate(MainActivity.java:19)  62 at android.app.Activity.performCreate(Activity.java:5146)  63 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1092)  64 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)  65 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2287)  66 at android.app.ActivityThread.access$600(ActivityThread.java:183)  67 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1288)  68 at android.os.Handler.dispatchMessage(Handler.java:99)  69 at android.os.Looper.loop(Looper.java:137)  70 at android.app.ActivityThread.main(ActivityThread.java:5252)  71 at java.lang.reflect.Method.invokeNative(Native Method)  72 at java.lang.reflect.Method.invoke(Method.java:511)  73 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:798)  74 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)  75 at dalvik.system.NativeStart.main(Native Method) 

xml

1<?xml version="1.0" encoding="utf-8"?> 2<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <ImageView 10 android:scaleType="centerCrop" 11 android:src="@drawable/back" 12 android:layout_width="match_parent" 13 android:layout_height="match_parent" /> 14 15 <ImageView 16 android:id="@+id/egg" 17 android:onClick="onEgg" 18 android:layout_alignParentBottom="true" 19 android:layout_centerHorizontal="true" 20 android:src="@drawable/egg0" 21 android:layout_width="wrap_content" 22 android:layout_height="wrap_content" /> 23 24</RelativeLayout>

java

1package com.example.myegg; 2 3import android.os.Bundle; 4import android.support.v7.app.AppCompatActivity; 5import android.view.View; 6import android.widget.ImageView; 7 8import java.util.Random; 9 10public class MainActivity extends AppCompatActivity { 11 12 // 準備 13 int count; 14 int answer; 15 16 @Override 17 protected void onCreate(Bundle savedInstanceState) { 18 super.onCreate(savedInstanceState); 19 setContentView(R.layout.activity_main); 20 21 // 初期化 22 count = 0; 23 answer = new Random().nextInt(5); 24 } 25 26 // 画像をタップ 27 public void onEgg( View v){ 28 count++; 29 if( count >2 ) { 30 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.egg1); 31 } 32 if( count >4 ) { 33 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.egg2); 34 } 35 if( count > 6 ) { 36 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.egg3); 37 } 38 if( count > 8 ) { 39 if( answer == 0 ) { 40 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.egga); 41 } 42 if( answer == 1 ) { 43 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.eggb); 44 } 45 if( answer == 2 ) { 46 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.eggc); 47 } 48 if( answer == 3 ) { 49 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.eggd); 50 } 51 if( answer == 4 ) { 52 ((ImageView)findViewById(R.id.egg)).setImageResource(R.drawable.egge); 53 } 54 } 55 } 56}

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

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

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

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

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

keicha_hrs

2019/05/26 11:13

Android Studioに限らず、統合開発環境(IDE)にはアプリケーションの動作のログを採取したり、ブレークポイントでプログラムを一時停止して1行ずつステップ実行したり、そのときの変数の内容を参照したりといった、問題を発見するための様々な機能が搭載されています。そうした機能を活用して問題を解決することが望ましいのですが、それでもどうしても解決できないときのために、どこまで検証したかを示した上で質問をするのが筋道でしょう。最低限、LogCatを活用して問題が発生している行を特定し、そのログと当該行周辺のコードを示すことは必須だと思います。
uhsi

2019/05/29 07:44

ご回答ありがとうございます。どのコードがエラーの原因となっているのかはわかりませんでした。エミュレーターでは成功していますのでコードには問題がないと思っていたのですが問題がある可能性はあるのでしょうか。
guest

回答1

0

ベストアンサー

画面を定義したXMLファイルがあるとおもいます。
その9行目の前後にエラーやワーニングがないか確認してみて下さい。

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myegg/com.example.myegg.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class ImageView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2234)

投稿2019/05/30 06:28

kamikaze.cappa

総合スコア558

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

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

uhsi

2019/05/30 07:31

ご回答ありがとうございます。「Missing contentDescription attribute on image less... (Ctrl+F1) Inspection info:Non-textual widgets like ImageViews and ImageButtons should use the contentDescription attribute to specify a textual description of the widget such that screen readers and other accessibility tools can adequately describe the user interface. Note that elements in application screens that are purely decorative and do not provide any content or enable a user action should not have accessibility content descriptions. In this case, just suppress the lint warning with a tools:ignore="ContentDescription" attribute. Note that for text fields, you should not set both the hint and the contentDescription attributes since the hint will never be shown. Just set the hint. See http://developer.android.com/guide/topics/ui/accessibility/checklist.html#special-cases. Issue id: ContentDescription」という表示がございましたが、なにか関係があるのでしょうか。
uhsi

2019/05/30 10:57

解決しました。本当にありがとうございました。今後の参考としてどのようにしてそのような情報を検索されたのか教えていただけないでしょうか。
kamikaze.cappa

2019/05/31 04:34

解決して良かったですね android.view.InflateException: Binary XML file line #9: Error inflating class ImageView のエラーからXMLに問題があるのだろうと思いました。 提示されたXMLを確認しましたが問題ありませんでした。 よって画像に問題あると考えました。 android.view.InflateException: Binary XML file line 上記をキーワードで検索すると該当ページが見つかります。 現象は同様な状態だと考えました。 以上です。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問