android.view.inflateException:バイナリXMLファイルライン#12:膨張してクラス<不明>

StackOverflow https://stackoverflow.com/questions/4512981

質問

Subjに表示されている種類の多くのエラーを受け取っています。これらのエラーは時々発生しているようで、私はそれらを再現することはできません。スタックから、さまざまなレイアウトリソースに対してこのようなエラーが発生する可能性があることがわかります。 XMLのラインもさまざまです。

このエラーが発生する理由を誰かが説明できますか?そして、この問題を解決するために私は何ができるでしょうか?

スタック

=============================================================

com.fsp.android.f generated the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fsp.android.f/com.life360.android.ui.tour.TourActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

--------- Stack trace ---------
1. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
2. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
3. android.app.ActivityThread.access$2200(ActivityThread.java:131)
4. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
5. android.os.Handler.dispatchMessage(Handler.java:99)
6. android.os.Looper.loop(Looper.java:123)
7. android.app.ActivityThread.main(ActivityThread.java:4702)
8. java.lang.reflect.Method.invokeNative(Native Method)
9. java.lang.reflect.Method.invoke(Method.java:521)
10. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12. dalvik.system.NativeStart.main(Native Method)
-------------------------------

----------- Cause -----------
android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

1. android.view.LayoutInflater.createView(LayoutInflater.java:513)
2. com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
3. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
4. android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
5. android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
6. android.view.LayoutInflater.inflate(LayoutInflater.java:382)
7. android.view.LayoutInflater.inflate(LayoutInflater.java:320)
8. android.view.LayoutInflater.inflate(LayoutInflater.java:276)
9. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
10. android.app.Activity.setContentView(Activity.java:1629)
11. com.solvek.sample.ui.BaseActivity.onCreate(BaseActivity.java:23)
12. com.solvek.sample.ui.tour.TourActivity.onCreate(TourActivity.java:161)
13. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
14. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
15. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
16. android.app.ActivityThread.access$2200(ActivityThread.java:131)
17. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
18. android.os.Handler.dispatchMessage(Handler.java:99)
19. android.os.Looper.loop(Looper.java:123)
20. android.app.ActivityThread.main(ActivityThread.java:4702)
21. java.lang.reflect.Method.invokeNative(Native Method)
22. java.lang.reflect.Method.invoke(Method.java:521)
23. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
24. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
25. dalvik.system.NativeStart.main(Native Method)
-----------------------------

-------- Environment --------
Time =2010-12-20 08:27:35 AM
Device =tmobile/htc_espresso/espresso/espresso:2.1-update1/ERE27/216830:user/release-keys
Make =HTC
Model =T-Mobile myTouch 3G Slide
Product =htc_espresso
App =com.fsp.android.f, version 2.0.9 (build 1232)

以下はXMLの結果ですが、そのようなエラーは他のXMLで発生します

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <ViewFlipper android:layout_gravity="fill" android:id="@+id/flipper" android:layout_height="fill_parent" android:layout_width="fill_parent">
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_1"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_2"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_3"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_4"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_5"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_6"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_7"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_8"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_9"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_10"/>
        <ImageView android:scaleType="fitXY" android:layout_width="fill_parent" android:layout_height="fill_parent" android:src="@drawable/tour_11"/>
    </ViewFlipper>

    <LinearLayout android:id="@+id/exit_bar" android:layout_gravity="top" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <Button android:background="@drawable/orange_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" android:textStyle="bold" android:textColor="#000000" android:shadowColor="#ffffff" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:id="@+id/exit_tour_btn" android:text="Exit" android:layout_marginLeft="20dip"/>
        <TextView android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_gravity="center" android:layout_width="110dip" android:layout_marginLeft="20dip" android:textSize="16dip" android:textStyle="bold" android:text="Life360 Tour"/>

    </LinearLayout>

    <Button style="@style/BlueBtn" android:text="Continue" android:layout_marginTop="40dip" android:id="@+id/continue_btn" android:visibility="gone" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_gravity="center" />

    <FrameLayout android:id="@+id/bottom_bar" android:layout_gravity="bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/blue_bar" android:visibility="invisible">
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/left" android:layout_gravity="left|center" android:background="@drawable/tour_left" android:layout_marginLeft="10dip"/>
        <ImageView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/right" android:layout_gravity="right|center" android:background="@drawable/tour_right" android:layout_marginRight="10dip"/>               
    </FrameLayout>
</merge>
役に立ちましたか?

解決

インフレの例外は実際には問題ではありませんが、実際にはレイアウトの別のより深い問題から来ており、その後、インフラ酸エクセプトに包まれています。一般的な問題は、描画可能なリソースをロードするImageViewを膨らませようとする際のメモリ外の例外です。このリソースの1つが高いピクセル解像度を持っている場合、多くのメモリが必要になり、膨張の例外が発生します。

したがって、基本的に、ドローブル画像のピクセル解像度がレイアウトに必要な最小値であることを確認してください。

他のヒント

ViewFlipper レイアウト膨張中にすべての画像をメモリにロードします。私の画像が大きいので、多くの記憶が必要です、私は置き換えました ViewFlipperImageSwitcher アニメーションのような画像を変更できます ViewFlipper しかし、その時点では1つの画像のみをロードします。

これは、aを使用する場合にも発生する可能性があります VectorDrawable サポートライブラリを使用して使用するのを忘れました app:srcCompat それ以外の android:src

正確なエラーは次のとおりです。 バイナリXMLファイルライン#XX:エラークラスの画像ビューエラー

そのリンクを参照してください

私は質問がすでに答えられていることを知っていますが、それでも誰かがこの種の問題に遭遇するかもしれないと考えて投稿しています。

私の場合の問題では、RES/レイアウト/フォルダーからレイアウトを参照し、RES/VALUES/DIMENSから@Dimensの値を参照する電話にアプリケーションをロードしています。 /dimens。

私は実際に既存のプロジェクトのUIを更新しています。

私はこの問題に遭遇しました。なぜなら、レイアウトフォルダー用のXMLを作成する際にヒント用のIDE ECLIPSEを使用しているため、値と値からのすべての値を表示します。

また、両方のファイルの値が異なる画面でマッピングされるのと同じであることも知っています。

これが誰かがこの種の愚かな問題に遭遇するのを助けるかもしれないことを願っています。

1つのコンストラクターのみでカスタムビューを作成するときに同じエラーがありました。カスタムビューのすべてのコンストラクターを定義してみてください。

   public CustomWebView(Context context) {
        super(context);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

私は同じバグに遭遇し、根本的な理由は次のとおりです。

アプリケーションコンテキストを使用してビューを膨らませます。

アクティビティコンテキストで膨張するバグが修正されました。

テーマをマテリアルテーマとして選択したため、このエラーがありました。しかし、4.4.2でアプリを実行しようとしていたとき、このエラーが発生しました。

解決策:Theme_holoをテーマとして選択します

私の写真サイズはたった14kbですが、問題はデザイナーが1011px x 1819pxを与えてくれたことです(解像度が高すぎるため、インフレーティングエクセプトを引き起こします)

誰かが同様の問題を抱えている場合、私はそのような問題を抱えていました。

View.inflate(getApplicationContext(), R.layout.my_layout, null)

交換することで修正されました getApplicationContext()this

このリンク あなたを助けるかもしれません。問題についてマニフェストをチェックしてみてください。もう一度発生できる場合は、スタックトレース全体を投稿して、エラーが実際に何であるかを確認できるようにします。

編集:これをチェックしたと確信していますが、Touractivityレイアウトに使用するXMLファイルの12行目は何ですか?

私にとって、エラーメッセージは実際にはログキャットでは不十分だったので、問題の原因を理解するために私がしたことは次のとおりです。

(ログ猫のエラーメッセージでは、homefragment.javaで特定のレイアウトを膨らませているときにエラーが発生したと述べました)

  1. レイアウトが膨らむ直前にブレークポイントを置きました
  2. その特定のブレークポイントに到達するまでデバッグモードでアプリケーションを実行しました
  3. カーソルでラインを選択して走りました Evaluate expression その上:
    • Run > Evaluate Expression また alt - F8
  4. 結果は、問題の原因に関する詳細情報を示しました。私の場合、それは描画可能なファイルでした。 tools:targetApi="lollipop" (バグは古いデバイスでのみ発生しました)。

私はそれが回答された質問であることを知っていますが、私が直面した原因を見ていません。

Android Studioが私のドローブルを /Drawable-V24に入れたのは、私のエミュレータがAPI 23です。

解決策は、すべてのドローブルを /描画可能なフォルダーに移動することでした(-24なし)。

「Drawable-24」フォルダーから「Drawable」フォルダーに画像ファイルをコピーする必要があります。

同じエラーがあり、DrawablesをDrawable MDPIからDrawable Folderに移動することを解決しました。 Android Studioでこれらの醜いランタイムエラーを得た間、Eclipseではすべてが完全に機能したため、気付くのに時間がかかりました。

編集注: EclipseからAndroid Studioに移行していて、プロジェクトがEclipseから来ている場合、Android StudioではEclipseとは少し異なることに注意してください。

私の場合、このエラーは私が使用するときに起こります フローティングアクションボタン とセット android:backgroundTint="#000". 。その後、設定しないでください backgroundTint 問題が解決しました。それがあなたに役立つことを願っています。

私は今この問題を抱えていて、それが何であるかを理解することができました。問題を引き起こしている私の価値の色を参照していました。ドロップダウンの提案から使用するのではなく、手動で定義しました。

API LVL 16でアプリを実行したときに同じエラーがありました(26は問題ありませんでした)。それは私が使ったからです ?attrr/colorAccent 私の形で描画可能:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="8dp" />

    <solid android:color="@attr/colorAccent" />

</shape>

それを通常の色に置き換えると、私の問題は修正されました。

私は同じ問題を抱えていましたが、描画可能なフォルダーの画像の前で(24)の描画可能なV24を削除し、それらを通常の描画可能物に置き換えることで解決しました。

私はこのスレッドが古いことを知っていますが、それでも誰も眠れない夜を過ごすべきではないように答えています。

私は古いプロジェクトをリファクタリングしていましたが、そのレイアウトファイルにはすべて、すべてのハードコードされた属性が含まれていました。 android:maxLength = 500. 。それで私はそれを自分に登録することにしましたres/dimen ASをファイルします <dimen name="max_length">500</dimen>.

RES-Valueでほぼ30のレイアウトファイルをリファクタリングしました。何だと思う?次回プロジェクトを実行したとき、それは同じものを投げ始めました InflateException.

解決策として、私のすべての変更をやり直し、以前と同じようにすべての値を保持する必要がありました。

tldr;

ステップ1:すべてが良いランニング。

ステップ2:メンテナンスをブーストするには、交換しました android:maxLength = 500<dimen name="max_length">500</dimen>android:maxLength = @dimen/max_length 、それはすべてがうまくいかなかったところです(でクラッシュします InflateException).

ステップ3:すべてが悪いランニング

ステップ4:もう一度交換して、すべての仕事をやり直す android:maxLength = @dimen/max_lengthandroid:maxLength = 500。すべてが修正されました。

ステップ5:すべてが良いランニング。

同じエラーが見つかりましたが、エラーが何であるかを識別するのに2日かかりました。

エラーは、私が1つを使用しようとしていたからです。 android:background

それよりも: app:srcCompat

SVGファイル。

あなたの場合、私はこれがそれだと思います

<ImageView 
    android:scaleType="fitXY" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/tour_11"      <-- the error is here !
 />

このように使用することをお勧めします

<androidx.appcompat.widget.AppCompatImageView  <-- use **AppCompatImageView** not **ImageView**
        android:scaleType="fitXY" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        app:srcCompat="@drawable/tour_11"
     />

これが役立つことを願っています。

私も同様の問題に直面しました。誰にとっても、これはコードのさまざまな悪い使用法の問題かもしれません。

  1. XMLの間違ったレイアウトタグ
  2. ImageViewに直接重いリソースをロードすると、その結果 ooom
  3. スタイルの使用に関する問題。

最も無視された要因の1つは、おそらくそうかもしれません 正しいコンテキストの使用 ビューを膨らませながら。使用していないことを確認してください ApplicationContext アクティビティコンテキストが必要な場合。その間、 ApplicationContext 常にエラーが発生しない可能性がありますが、ビューの階層に応じて重要である可能性があります。

私は自分の問題を悪い文脈で解決しました(使用して ApplicationContext それ以外の アクティビティ 4日間で!それが解決した場合に試してください。ハッピーコーディング!!

私は同じ問題に直面していたので、ビューの代わりにXMLでビュータグを使用していました。クラスを表示するために交換すると、問題が修正されました。

それがあなたにも役立つことを願っています。

APIバージョンを確認する必要があります。私は自分に背景色を与えていました LinearLayout お気に入り

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/as_royalblue"
        android:orientation="vertical"></LinearLayout>

確かに私は同じエラーがありました、 as_royalblue.xml 中身 drawable フォルダ

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="90"
        android:endColor="@color/royalblue_s"
        android:startColor="@color/royalblue_e" />
</shape>

そして、私がそれを修正した方法, 、実際にはAPIの問題のように思われるため、APIレベルがAPI 24を超えている場合は、好きなように使用できるようにする必要があります。しかし、24歳未満の場合は、使用を避ける必要があります。ジュットは通常の色を与えます。

fun checkAPI_N(): Boolean {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N)
            return true
        else
            return false
    }

LinearLayoutsにIDを与え、その問題がある場合は背景を設定します

 if(UtilKotlin.checkAPI_N()){
            linlay_act_menu_container.setBackgroundResource(R.drawable.a_6)
            linlay_act_menu_logo.setBackgroundResource(R.drawable.as_strain)
        }else {//todo normal color background setting}

私の場合、レイアウトファイルで使用するライブラリUIコンポーネントの完全なパッケージ名を指定する必要があります。

私にとっては、XMLベクトルグラフィックスイメージと同じレイアウトファイルに通常のPNGを組み合わせようとしたために起こりました。

XMLベクトルグラフィックスをPNGSに置き換えた後にのみ、動作し始めました

  • この問題を解決するだけで、描画可能な画像(V24)から画像を削除し、描画可能なフォルダーに貼り付けてください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top