Domanda

Sto ricevendo molti errori di tipo visualizzato nel subj. Questi errori sembra essere occasionale e non li possono riprodursi. Da pila posso imparare che tale maggio errore si verifica per le mie diverse risorse di layout. La linea di XML è anche variabile.

Qualcuno può spiegare perché si verifica questo errore? E che cosa posso fare per risolvere questo problema?

Stack

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

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)

Ecco il risultato di XML, tuttavia tale errore si verifica in altri XMLs

<?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>
È stato utile?

Soluzione

L'eccezione gonfiare in realtà non è il problema, ma in realtà viene da un altro problema più profondo nel layout che viene poi avvolto in un InflateException. Un problema comune è un'eccezione di memoria quando si cerca di gonfiare un ImageView il caricamento di una risorsa disegnabile. Se una di queste risorse ha una risoluzione di pixel ci vorrebbe un sacco di memoria causando quindi un'eccezione gonfiaggio.

Quindi, in pratica verificare che la risoluzione in pixel nelle immagini drawable sono solo il minimo necessario per il layout.

Altri suggerimenti

carichi ViewFlipper tutte le immagini in memoria durante il layout di gonfiaggio. Perché le mie immagini sono grandi ci vogliono molti di memoria, ho sostituito con ViewFlipper ImageSwitcher che può cambiare le immagini con l'animazione come ViewFlipper ma carichi di una sola immagine alla volta.

Questo può succedere anche se si utilizza un VectorDrawable utilizzando libreria di supporto e si è dimenticato di usare al posto di app:srcCompat android:src

errore esatto è: Binary linea di file XML #XX: Errore classe gonfiaggio ImageView

Vedi che puntano

So che la domanda è già una risposta, ma ancora sto distacco con il pensiero che potrebbe dirigere qualcuno in questo tipo di problema.

Nel mio caso problema è che io sono caricando la mia domanda di telefono che si riferiscono layout da res / layout / cartella e valori per @dimens da res / valori / Dimens qui è font_22 che si sta cercando di accesso e si definiscono in res / I valori-XLarge / dimens.

In realtà sto aggiornando UI del progetto esistente.

mi sono imbattuto in questo problema perché sto utilizzando IDE Eclipse dove ho Ctrl + spazio per suggerimento durante la scrittura di XML per il layout della cartella vengono visualizzati tutti i valori dai valori così come cartella di valori-xlarge indipendentemente per il quale cartella che sto scrivendo .

So anche che i valori in entrambi i file devono essere lo stesso per mappato per gli schermi differenti.

Spero che questo può aiutare qualcuno imbattersi in questo tipo di problema stupido.

Ho avuto lo stesso errore durante la creazione visualizzazione personalizzata con un solo costruttore, cercare di definire tutte costruttore per le visualizzazioni personalizzate.

   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();
    }

ho incontrato lo stesso problema e ha trovato la ragione principale è:

Usa Applicazione Context alla visualizzazione gonfiare.

gonfiaggio con contestuale attività Corretto il bug.

ho avuto questo errore perché ho scelto come tema Materiale tema. Ma come ho cercato di eseguire app su 4.4.2 ha dato questo errore.

Soluzione: Selezionare Theme_holo come tema

La mia dimensione immagine è solo 14Kb ma il problema è che il progettista mi ha dato 1011px x 1819px (risoluzione troppo alta, quindi, causando l'InflateException)

Nel caso in cui qualcuno ottiene problemi simili, ho avuto un simile problema, mentre gonfiare la vista:

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

fisso sostituendo getApplicationContext() con this

Questo collegamento può aiutare . Prova a controllare nel vostro manifesto problemi. Se si può ottenere che accada di nuovo, inserire il vostro intero stack trace in modo che possiamo vedere ciò che l'errore è in realtà.

EDIT: Sono sicuro che avete controllato questo, ma quello che è sulla linea 12 del file XML che si utilizza per il layout TourActivity

?

Per quanto mi riguarda, il messaggio di errore era in realtà insufficienti nel gatto registro, ecco quello che ho fatto per capire che cosa ha causato il problema:

(Nel messaggio di errore di registro gatto, ha detto si è verificato l'errore durante gonfiando un layout specifico nel mio HomeFragment.java)

  1. ho messo un punto di interruzione poco prima che il layout è stato gonfiato
  2. I correva l'applicazione in modalità di debug, fino a raggiungere quella specifica punto di interruzione
  3. Ho selezionato la linea con il mio cursore e corse Evaluate expression su di esso:
    • Run > Evaluate Expression o alt - F8
  4. Il risultato mi ha mostrato ulteriori informazioni sulla fonte del problema, che nel mio caso, era un file utilizzando disegnabile tools:targetApi="lollipop" (il bug si è verificato solo sui dispositivi più vecchi).

Lo so che è una domanda ha risposto, ma non vedo la causa che ho affrontato.

E 'stato che Android Studio collocato miei drawable in / drawable-V24 Il mio emulatore è API 23. Quindi, alla fine non riesce a trovarlo.

La soluzione era quella di spostare tutti drawable a / cartella drawable (senza -24).

You should copy the image files from the "drawable-24" folder to the "drawable" folder.

I had the same error and I solved moving my drawables from the folder drawable-mdpi to the folder drawable. Took me some time to realize because in Eclipse everything worked perfectly while in Android Studio I got these ugly runtime errors.

Edit note: If you are migrating from eclipse to Android Studio and your project is coming from eclipse it may happen, so be careful that in Android Studio things a little differs from eclipse.

In my case,this error happen when I use the Floating action button and set android:backgroundTint="#000". Then just don't set backgroundTint and problem solved. Hope it's helpful for you.

I had this problem just now and managed to figure out what it was. Was referencing a colour in my values that was causing problems. So defined it manually instead of using one from the dropdown suggestions.Then it worked!

I had same error when I ran my app on API lvl 16 (26 was fine). It was because I used ?attrr/colorAccent in my shape drawable:

<?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>

Replacing that with a regular color fixed my problem.

i had the same issue and it solved by removing drawable-v24 with (24) in front of images in drawable folder and replacing them with ordinary drawables.

I know this thread is old, but still answering it so that no-one else should spend sleepless nights.

I was refactoring an old project, whose layout files all contained hardcoded attributes such as android:maxLength = 500. So I decided to register it in my res/dimen file as <dimen name="max_length">500</dimen>.

Finished refactoring almost 30 layout files with my res-value. Guess what? the next time I ran my project it started throwing the same InflateException.

As a solution, needed to redo my all changes and keep all-those values as same as before.

TLDR;

step 1: All running good.

step 2: To boost my maintenance I replaced android:maxLength = 500 with <dimen name="max_length">500</dimen> and android:maxLength = @dimen/max_length , that's where it all went wrong(crashing with InflateException).

step 3: All running bad

step 4: Re-do all my work by again replacing android:maxLength = @dimen/max_length with android:maxLength = 500.Everything got fixed.

step 5: All running good.

I found the same error, and it took two days to identify what the error was.

The error was simply because I was trying to use one: android:background

Rather than: app:srcCompat

in an SVG file.

In your case, I believe this is it

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

I recommend using it this way

<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"
     />

I hope this helps.

I also faced a similar issue. While for anyone this may be an issue of various bad usages in Code such as

  1. Wrong Layout tag in XML
  2. Loading of heavy resource directly into ImageView resulting in OOM
  3. Issues with usage of styles.

One most ignored factor may be usage of correct Context while inflating views. Please check that you are not using ApplicationContext where an Activity context is required. While, ApplicationContext may not end up in error always, but depending upon your view hierarchy it may be crucial.

I resolved my issue with a BAD context (using ApplicationContext instead of Activity in a span of 4 days! So try if that solves. Happy Coding!!

I had faced the same issue, I had used view tag in xml instead of View. Replacing to View class fixed the issue.

Hope it helps for you too..

We need to check API Version. I used to give background color to my LinearLayout like

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

for sure I had the same error, as_royalblue.xml inside drawable folder

<?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>

and how I fixed it, actually it seems Api problem so we need to check the api level if it is above API 24 so we are able to use the way we like. But if it is under 24 we need to avoid usage, juts give a normal color or one color not color gradential mixed one.

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

give id to your linearlayouts and set backgrounds if its ok

 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}

In my case I've to specify the complete package name of library UI component that I use in my layout file.

For me it happened because I tried to mix xml vector graphics images with ordinary png in the same layout file,

only after I replaced the xml vector graphics with pngs it started to work

  • I just solve this issue just delete your images from drawable(v24) and just paste it in drawable folder this works for me.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top