0

I'm getting a runtime exception in my code that says : java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abiel.contacts/com.example.abiel.contacts.Data}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.relative.RelativeLayout

Here's my layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.relative.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:id="@+id/ContactImage"
            android:layout_gravity="center_vertical"
            android:layout_alignParentTop="true"

            />

        <EditText
            android:layout_width="294dp"
            android:layout_height="wrap_content"
            android:id="@+id/editName"
            android:inputType="text"
            android:textSize="24sp"
            android:hint="Please write your name"
            android:textColorHint="#ff84eb"
            android:layout_centerVertical="true"
            />

        <EditText
            android:layout_width="296dp"
            android:layout_height="wrap_content"
            android:id="@+id/editNumber"
            android:inputType="number"
            android:textSize="24sp"
            android:hint="Enetr your number"
            android:textColorHint="#ff9cda"
            android:layout_above="@+id/editEmail"
            />

        <EditText
            android:layout_width="297dp"
            android:layout_height="wrap_content"
            android:id="@+id/editEmail"
            android:inputType="textEmailAddress"
            android:textSize="24sp"
            android:hint="Please write your E-mail"
            android:textColorHint="#ff96ea"
            android:layout_above="@+id/save"
            />

        <Button
            android:layout_width="171dp"
            android:layout_height="wrap_content"
            android:id="@+id/save"
            android:text="Save"
            android:layout_gravity="center_horizontal"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="86dp"
            android:background="#000000"
            android:textColor="#ff0009"
            android:textStyle="bold"/>

</android.support.relative.RelativeLayout>
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Bubba
  • 151
  • 1
  • 9
  • 1
    Remove comment from ~setContentView~ method – akhilesh0707 Feb 11 '18 at 03:16
  • when I use that line I get this runtime exception java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.abiel.contacts/com.example.abiel.contacts.Data}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class android.support.relative.RelativeLayout, it doesn't like my layout file not sure why I'll edit the post to show what the file looks like – Bubba Feb 11 '18 at 03:26
  • post your XML code along with question – akhilesh0707 Feb 11 '18 at 03:28
  • `InflateException` doesn't tell you much. Look further on in the stack trace for the root cause. – Mike M. Feb 11 '18 at 03:31
  • I see a class not found exception : – Bubba Feb 11 '18 at 03:37
  • Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.relative.RelativeLayout" on path: DexPathList[[zip file "/data/app/com.example.abiel.contacts ..... How could it not recognize relative layout – Bubba Feb 11 '18 at 03:38
  • use only `RelativeLayout` instead of ` – akhilesh0707 Feb 11 '18 at 03:45

2 Answers2

1

Your variable would not be initialized because you did not set view on Activity, you need to remove comment from //setContentView(R.layout.activity_second);

Update: Use only <RelativeLayout> instead of <android.support.relative.RelativeLayout, remove android.support.relative

akhilesh0707
  • 6,709
  • 5
  • 44
  • 51
1

As akhilesh0707 mentioned in his comment, you have removed the code to setContentView, which means that there is no layout attached to the activity. As a result, you are trying to define views without any layout to reference, so the views are not being instantiated correctly.

Simply uncommenting out the setContentView should solve your problem.

PGMacDesign
  • 6,092
  • 8
  • 41
  • 78