мое приложение вылетает на устройствах с API 21 и ниже - PullRequest
0 голосов
/ 29 сентября 2018

Я работаю над приложением для Android, и когда я тестирую его на устройствах / эмуляторах с API 21 и ниже, он вылетает и выдает мне сообщение в журналах:

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)

, если я удаляю элементы XML,приложение запускается и запрашивает MainActivity, и, кажется, размеры экрана не влияют на результат, который, по моим наблюдениям, связан с API, но я могу ошибаться

Вот код XML

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

Я попытался очистить некоторые ненужные атрибуты XML, но это не помогло. Что мне делать дальше?

1 Ответ

0 голосов
/ 29 сентября 2018

это довольно просто вставить ваше изображение в drawable и изменить путь в app \ src \ main \ res \ drawable

...