android.view.inflateexception binary xml file line #1 error inflating class android.widget.relativeLayout

前端 未结 7 1250
春和景丽
春和景丽 2021-02-07 07:56

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 th

相关标签:
7条回答
  • 2021-02-07 08:17

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

    android:background="@color/backgroundColor" 
    

    or

    android:background="@drawable/backgroundimg"
    
    0 讨论(0)
  • 2021-02-07 08:19

    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!

    0 讨论(0)
  • 2021-02-07 08:20

    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" />**
    
    0 讨论(0)
  • 2021-02-07 08:22

    You have to change

    android:background="@layout/activity_main"
    

    to

    android:background="@drawable/yourImageName"
    
    0 讨论(0)
  • 2021-02-07 08:32

    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"
    
    0 讨论(0)
  • 2021-02-07 08:32

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

    0 讨论(0)
提交回复
热议问题