0

Im working on an android app and when I test it on devices/emulators with api 21 and lower it crashes and gives me a message in the logs:

09-29 07:32:30.349 6212-6212/org.jazmawy.mahmood.vocabulary 
E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.jazmawy.mahmood.vocabulary, PID: 6212
java.lang.RuntimeException: Unable to start activity 

 ComponentInfo{org.jazmawy.mahmood.vocabulary/org.jazmawy.mahmood.vocabulary.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class ImageView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
 Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class ImageView
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
    at 
org.jazmawy.mahmood.vocabulary.MainActivity.onCreate(MainActivity.java:52)

if I remove the XML elements the app launches and prompts to MainActivity and It seems that screen sizes doesn't affect the result to my observation its due to the API but i could be wrong

Here is the XML code

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context=".MainActivity">

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.4"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/green"
    android:contentDescription="@string/app_name" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="4dp"
    android:layout_marginTop="16dp"
    android:orientation="vertical"
    android:weightSum="4"
    app:layout_constraintBottom_toTopOf="@+id/mainActivityAdView"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <Button
        android:id="@+id/button11"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/vocabulary_button"
        android:onClick="openUnitActivity" />

    <Button
        android:id="@+id/button13"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/collection_button"
        android:onClick="collectionOnClick" />

    <Button
        android:id="@+id/button9"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/contact_us_button"
        android:onClick="contactsUsOnClick" />

    <Button
        android:id="@+id/button14"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="@drawable/aboutus_button"
        android:onClick="aboutUsOnClick" />

</LinearLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/mainActivityAdView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    ads:adSize="BANNER"
    ads:adUnitId="AD_UNIT_ID"
    app:layout_constraintStart_toStartOf="parent" />

</android.support.constraint.ConstraintLayout>

I tried cleaning some unnecessary XML attributes but it doesn't help What should I try next?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Wild_MJ
  • 37
  • 9
  • 1
    Make sure your `@drawable/green` is placed inside **`drawable`** not in **`drawable-v24`** – AskNilesh Sep 29 '18 at 07:50
  • how do i do that, it automatically put every single image in (v24) – Wild_MJ Sep 29 '18 at 07:52
  • just simple open `drawable-v24` folder and cut paste your image inside `drawable` – AskNilesh Sep 29 '18 at 07:53
  • the images are inside directory named drawable but the image name is green.jpg (v24), if that makes sense – Wild_MJ Sep 29 '18 at 07:55
  • sorry i might sounded like an idiot, but i figured out how to put images in drawable nad not drawable-v24 ill comment hat happens when i finish copying the images – Wild_MJ Sep 29 '18 at 08:02

1 Answers1

0

its quite simple paste your image into the drawable and change tha path into app\src\main\res\drawable

Sachin Solanki
  • 79
  • 2
  • 15
  • i did and im now getting this error, I dont know if its realated to the drawable-v24 problem earlier `09-29 08:08:33.820 8855-8933/org.jazmawy.mahmood.vocabulary E/eglCodecCommon: glUtilsParamSize: unknow param 0x000085b5` – Wild_MJ Sep 29 '18 at 08:10