0

im trying to put an imageview at the top to show a logo but when i run the app i have this error:

android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.ImageView

if i delete that imageview the code runs without a problem

how i can solve this here is activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="#2e3138"

    tools:context="dattasolutions.cloud.dattasolutionscloud.MainActivity"
    android:orientation="vertical"
  >
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="60dp"
        android:src="@drawable/logo"
        android:id="@+id/imageView"
        />

    <TextView

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textSize="17sp"
        android:id="@+id/tvHeading"
        android:text="Presiona el icono para subir archivos al servidor"
        android:textColor="#fff"
        android:textStyle="bold"
        android:layout_marginTop="64dp" />
    <ImageView
        android:id="@+id/ivAttachment"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/attach_icon"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_x="145dp"
        android:layout_y="171dp" />

    <TextView
        android:id="@+id/tv_file_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#fff"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:layout_below="@+id/ivAttachment"
        android:layout_centerHorizontal="true"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/b_upload"
        android:text="Upload"
        android:textStyle="bold"
        android:textSize="20sp"
        android:layout_alignParentBottom="true"
        android:gravity="center"
        android:textColor="#fff"
        android:background="#039be5"/>



</RelativeLayout>

enter image description here

jtaco263
  • 43
  • 1
  • 10

2 Answers2

2

Try to Replace. android:src="@drawable/logo"

With.
app:srcCompat="@drawable/logo"
See reason.

And if it still doesn't work then check the size of the image. Some times it is not actually the inflating problem but a deeper one i.e. Memory issue leading to inflation exception. Use an image with minimum necessary size. Hope it helps.

Niraj Niroula
  • 2,376
  • 1
  • 17
  • 36
0

May be the problem is in your image named "logo" try some other image and check whether it's the problem of image format or size etc. In this way you'll easily come to know about the problem and what type of image should you use in the future. Good Luck!

Ali Khan
  • 61
  • 2
  • 10