-1

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.joystick.myapplication/com.example.joystick.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout

i keep getting this error

 <?xml version="1.0" encoding="utf-8"?>

 <RelativeLayout 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"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp">


    <Button
        android:id="@+id/sendButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/writeMsg"
        android:layout_alignBottom="@+id/writeMsg"
        android:layout_toEndOf="@+id/onOff"
        android:layout_toRightOf="@+id/onOff"
        android:text="Send"
        tools:layout_editor_absoluteX="139dp"
        tools:layout_editor_absoluteY="111dp" />

    <ListView
        android:id="@+id/peerListView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="260dp" />

    <EditText
        android:id="@+id/writeMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="63dp"
        android:layout_marginStart="63dp"
        android:layout_toEndOf="@+id/back"
        android:layout_toRightOf="@+id/back"
        android:ems="10"
        android:inputType="textPersonName"
        tools:layout_editor_absoluteX="35dp"
        tools:layout_editor_absoluteY="429dp" />


    <Button
        android:id="@+id/onOff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/connectionStatus"
        android:layout_marginLeft="75dp"
        android:layout_marginStart="75dp"
        android:layout_toEndOf="@+id/readMsg"
        android:layout_toRightOf="@+id/readMsg"
        android:text="Wifi On"
        tools:layout_editor_absoluteX="73dp"
        tools:layout_editor_absoluteY="77dp" />

    <Button
        android:id="@+id/discover"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/readMsg"
        android:layout_alignRight="@+id/readMsg"
        android:layout_below="@+id/connectionStatus"
        android:text="discover"
        tools:layout_editor_absoluteX="155dp"
        tools:layout_editor_absoluteY="0dp" />

    <TextView
        android:id="@+id/readMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/writeMsg"
        android:layout_alignEnd="@+id/writeMsg"
        android:layout_alignRight="@+id/writeMsg"
        android:layout_marginBottom="24dp"
        android:layout_marginEnd="65dp"
        android:layout_marginRight="65dp"
        android:text="Message"
        android:textAlignment="center"
        android:textSize="20sp"
        android:textStyle="italic"
        tools:layout_editor_absoluteX="132dp"
        tools:layout_editor_absoluteY="373dp" />

    <TextView
        android:id="@+id/connectionStatus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:text="Connection Status"
        android:textAlignment="center"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="18sp"
        android:textStyle="italic"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="16dp" />

    <Button
        android:id="@+id/back"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/back"
        android:visibility="visible" />
   </RelativeLayout>
bouhmid
  • 15
  • 1
  • 6

1 Answers1

0

It is a long shot but i think that you are trying to load a big(size in MB) picture. What I can recommend is to reduce the size of the picture with 50% and I think your problem it will be fixed.

Goodluck :)

EDIT:

Here is how it looks when i runt it on 5.5 inch device:

HERE IS THE IMAGE

It is running good also oon my phone. So please check the MB size of the following pictures:

"@drawable/drone
and
"@drawable/image_button_bg"

EDIT:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">

    <Button
        android:id="@+id/sendButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/writeMsg"
        android:layout_alignBottom="@+id/writeMsg"
        android:layout_toEndOf="@+id/onOff"
        android:text="Send"/>

    <ListView
        android:id="@+id/peerListView"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentStart="true"
        android:layout_centerVertical="true"/>

    <EditText
        android:id="@+id/writeMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="63dp"
        android:layout_toEndOf="@+id/back"
        android:ems="10"
        android:inputType="textPersonName"/>

    <Button
        android:id="@+id/onOff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/connectionStatus"
        android:layout_marginStart="75dp"
        android:layout_toEndOf="@+id/readMsg"
        android:text="Wifi On" />

    <Button
        android:id="@+id/discover"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignEnd="@+id/readMsg"
        android:layout_below="@+id/connectionStatus"
        android:text="discover"/>

    <TextView
        android:id="@+id/readMsg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/writeMsg"
        android:layout_alignEnd="@+id/writeMsg"
        android:layout_marginBottom="24dp"
        android:layout_marginEnd="65dp"
        android:text="Message"
        android:textAlignment="center"
        android:textSize="20sp"
        android:textStyle="italic"/>

    <TextView
        android:id="@+id/connectionStatus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:text="Connection Status"
        android:textAlignment="center"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="18sp"
        android:textStyle="italic"/>

    <Button
        android:id="@+id/back"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/back"
        android:visibility="visible" />
</RelativeLayout>

Ty this as XML and see what happens. If you still getting the error it means that the problem is somewhere else.

  • i deleted the backgroud picture still nothing :/ by the way i tryed my code with a virtual machine with 4.9 screen size it worked well but when i tried it on my device 5.5 or another avd its at that time whene i get this error – bouhmid May 02 '18 at 14:15
  • @bouhmid it should be one of the pictures you are using since I tested the layout you posted and it is working with my images. – Dimitar Georgiev May 02 '18 at 14:26
  • thanks man its worked but i have to ask how to get the proper image for my app and whats the size limit mine was 29.81 K – bouhmid May 02 '18 at 15:22
  • I am glad to hear that it is working. May be you can accept the answer as correct as a compensation :)....About the max image sizes it really depends on the device. As far as i know is that every App has some limitation of memory that can use before it gets killed. Maybe your the application is using that much memory because of all of the `RelativeLayouts` you have nested inside of the `MainActivity`. May be it will be better if you try to make all the design in one `RelativeLyaout`. Explanation about the image: [link][https://stackoverflow.com/questions/2131947/android-memory-allocation] – Dimitar Georgiev May 02 '18 at 15:31
  • what about this error android.view.InflateException: Binary XML file line #105: Binary XML file line #105: Error inflating class – bouhmid May 02 '18 at 16:25
  • The inflation fails because the app is running out of memory. You need to track down the real cause of the memory leaks. Just fix your layout and make the design in one `RelativeLayour`..dont forget to accept the answer :) – Dimitar Georgiev May 03 '18 at 08:16
  • I added my xml file with inflation class leaks . ps : am new i dont know how to accept :p – bouhmid May 03 '18 at 09:47
  • I will try to fix it and post it in new answer. Accept answer means you need to press the ✓ symbol of the answer. – Dimitar Georgiev May 03 '18 at 10:08
  • @bouhmid please see my edit with the new version of the `XML` – Dimitar Georgiev May 03 '18 at 10:11
  • with this XML that i posted in my edit it is working fine! – Dimitar Georgiev May 03 '18 at 10:13