android.view.InflateException:二进制XML文件行#20:错误类膨胀类Relativelayout

时间:2016-11-24 06:52:22

标签: android xml android-layout android-relativelayout

我是android的新手。 我刚刚制作了4个textview和1个相对布局的布局。但是当我运行它时出现错误android.view.InflateException:二进制XML文件行#20:错误在logcat中膨胀类Relativelayout。我的代码

xml代码

<LinearLayout 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:orientation="vertical"
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="com.gpsaja.GPSMainActivity" >

<TextView
    android:id="@+id/tvAddress"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" 
    android:layout_gravity="center"
    android:textStyle="bold"/>

<Relativelayout
    android:id="@+id/cantainer_layout"
    android:layout_width="match_parent"
    android:layout_height="260dp"
    android:background="#ffffff"
    android:layout_gravity="center">
    </Relativelayout>

<TextView
    android:id="@+id/tvDegree"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="@string/idDegree"
    android:textSize="20sp"
    android:textStyle="bold" />

<LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="horizontal"
    >

    <TextView
        android:id="@+id/tvLat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/idLat" 
        android:gravity="center"/>

    <TextView
        android:id="@+id/tvLong"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/idLon" />
</LinearLayout>

logcat的

11-24 01:24:51.056: E/AndroidRuntime(1792): FATAL EXCEPTION: main
11-24 01:24:51.056: E/AndroidRuntime(1792): Process: com.gpsaja, PID: 1792
11-24 01:24:51.056: E/AndroidRuntime(1792): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gpsaja/com.gpsaja.GPSMainActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class Relativelayout
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread.access$800(ActivityThread.java:135)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.os.Handler.dispatchMessage(Handler.java:102)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.os.Looper.loop(Looper.java:136)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread.main(ActivityThread.java:5001)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at java.lang.reflect.Method.invoke(Method.java:515)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at dalvik.system.NativeStart.main(Native Method)
11-24 01:24:51.056: E/AndroidRuntime(1792): Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class Relativelayout
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:707)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.Activity.setContentView(Activity.java:1929)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at com.gpsaja.GPSMainActivity.onCreate(GPSMainActivity.java:43)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.Activity.performCreate(Activity.java:5231)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
11-24 01:24:51.056: E/AndroidRuntime(1792):     ... 11 more
11-24 01:24:51.056: E/AndroidRuntime(1792): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.Relativelayout" on path: DexPathList[[zip file "/data/app/com.gpsaja-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.gpsaja-1, /system/lib]]
11-24 01:24:51.056: E/AndroidRuntime(1792):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.createView(LayoutInflater.java:559)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:652)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
11-24 01:24:51.056: E/AndroidRuntime(1792):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
11-24 01:24:51.056: E/AndroidRuntime(1792):     ... 21 more

帮我解决。

6 个答案:

答案 0 :(得分:3)

您需要使用.css({ border:'0px', solid: '#f00', margin:'5px 0px',font-size: '14px' }) 代替RelativeLayout

Relativelayout

答案 1 :(得分:3)

只需将您的拼写Relativelayout更改为RelativeLayout。 Android studio还可以帮助您在xml中编写代码。当你只输入&#34; Rel&#34;它应该是show popup你选择不需要写完整的拼写。

答案 2 :(得分:2)

将Relativelayout替换为RelativeLayout

答案 3 :(得分:1)

替换相对布局代码
 <RelativeLayout
    android:id="@+id/cantainer_layout"
    android:layout_width="match_parent"
    android:layout_height="260dp"
    android:background="#ffffff"
    android:layout_gravity="center">
</RelativeLayout>

答案 4 :(得分:1)

RelativeLayout 。 为什么使用空的 RelativeLayout ? 如果您使用它来创建空格,请改用查看

答案 5 :(得分:0)

谢谢你。通过将Relativelayout更改为RelativeLayout,将其修复。