17

I am new in android.
I just made a new layout with one text bar and 2 buttons but it didn't work, I am posting the stack trace and my relative layout file any idea about this? I saw the same question there which says to decrease the draw able size. But it didn't help in my case or I didn't now much about how to decrease it. Here is some of my stack trace:

  D/AndroidRuntime(1192): Shutting down VM
W/dalvikvm(1192): threadid=1: thread exiting with uncaught exception (group=0xb60cc4f0)
E/AndroidRuntime(1192): FATAL EXCEPTION: main
E/AndroidRuntime(1192): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellomissworld/com.example.hellomissworld.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.widget.RelativeLayout
E/AndroidRuntime(1192):at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
12-24 18:58:31.451: E/AndroidRuntime(1192):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-24 18:58:31.451: E/AndroidRuntime(1192):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-24 18:58:31.451: E/AndroidRuntime(1192):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

and that is the xml file of lay out :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@layout/activity_main"
    android:focusable="false"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_marginTop="24dp"
        android:ems="10"
        android:inputType="text" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_alignParentTop="true"
        android:text="@string/typehere"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:text="@string/ok" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/editText1"
        android:layout_toLeftOf="@+id/button2"
        android:text="@string/cancel" />

</RelativeLayout>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
jazz b
  • 437
  • 1
  • 6
  • 15

7 Answers7

15

You have to change

android:background="@layout/activity_main"

to

android:background="@drawable/yourImageName"
Piyush
  • 18,895
  • 5
  • 32
  • 63
13

Sometimes this error can also pop up when you are using a large image that is actually too big that leads to a memory error and crashes your app. If you are using background images or any large assets make sure they exist and that they aren't too big and then you'll be singing in the rain!

Chris Klingler
  • 5,258
  • 2
  • 37
  • 43
9

this line is indicating the first line of the layout:

android.view.InflateException: Binary XML file line #1: Error inflating class 

and at the first line there is Relative layout declaration:

So The error is on android:background, and This is not the correct way to set background of layout:

android:background="@layout/activity_main"

it should be a color or drawable image

android:background="@color/backgroundColor" or android:background="#012345"

or

android:background="@drawable/backgroundimg"
Hamad
  • 5,096
  • 13
  • 37
  • 65
3

This is wrong android:background="@layout/activity_main" should be

android:background="@color/backgroundColor" 

or

android:background="@drawable/backgroundimg"
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
  • @jazzb Yes this is the reason because layout are used for Activity to display on the Screen. – Piyush Dec 24 '13 at 14:51
3

What fixed it in my case was to change the location of my color.xml

As I copied it from some other project of mine and pasted it in the new project, Android Studio placed it in the v21 folder, meaning my emulator (v19) could not reach the resource file color.xml.

I did the following to fix it:

  1. Right click on color.xml.
  2. Select Refactor > Move.
  3. On the dialog that open, removed the suffix -v21.

Now, my "old" emulator was able to read the file.

I hope it helps..

Barakuda
  • 790
  • 8
  • 16
  • This fixed it for me, thanks. Same thing, copied from other project. The addition to my folder names was different to yours - mine was with the suffix w820dp – CHarris Apr 20 '16 at 23:33
0

I had the same problem - but in a activity that had no background image.

I found out that the GUI editor (when using Eclipse - I don't know about Android Studio) sometimes adds the buggy property without any reason:

android:background="@layout/activity_main"

I'm not sure why the editor does so - maybe it is a bug or simply a usage error.

However if the activity does not have a background image the entire property simply has to be deleted!

Martin Rosenau
  • 17,897
  • 3
  • 19
  • 38
-1

If you use Google Play Services and show Maps you should add Meta tag in AndroidManifest.xml

**<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />**
Akshay
  • 348
  • 4
  • 12