【问题标题】:Error parsing XML:no element found - How can I fix this bug?解析 XML 时出错:找不到元素 - 如何修复此错误?
【发布时间】:2018-05-30 08:19:45
【问题描述】:

请帮我修复这些错误,我正在制作一个应用程序,运行此应用程序时出现这些错误,

代码:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.shivamx.test_splash.Home_test"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@color/backgroundcolor">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_green"
                    android:padding="10dp"
                    android:src="@drawable/ic_inbox_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Engineering"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_yelow"
                    android:padding="10dp"
                    android:src="@drawable/ic_bba_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="BBA"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>





    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_pink"
                    android:padding="10dp"
                    android:src="@drawable/ic_bsc_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="BSc"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_purple"
                    android:padding="10dp"
                    android:src="@drawable/ic_llb_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="LLB"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>






    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_blue_aboutme"
                    android:padding="10dp"
                    android:src="@drawable/ic_about_me_box_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="About Me"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="About The Creator"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>



</LinearLayout>

这些文件存在于文件夹 res/layouts 中。仍然有错误。我该怎么办?
请快点说。

【问题讨论】:

  • 与问题分享您的 activity_home_test.xml 文件
  • 不要发布代码图像。并且不要发布错误图片。
  • 验证工具:context="com.example.shivamx.test_splash.Home_test" 是正确的。并验证所有资源是否存在
  • Please tell fast. 为什么您认为您的问题对我们来说如此紧迫?匆匆忙忙找谁来帮你(在空闲时间免费)太烦人了。

标签: android gridview


【解决方案1】:

从外观上看,activity_home_test.xml 不存在于您的res/layout/ 目录中。

【讨论】:

  • 文件在那里,兄弟。
  • @ShivamPokhriyal 比与问题分享它
  • 发布activity_home_test.xml的内容
  • 请检查兄弟@Nate
  • @ShivamPokhriyal 你只是忘了关闭你的父母 更正它
【解决方案2】:

你的代码是正确的你只是忘了关闭你的父母&lt;LinearLayout&gt;更正它

只需关闭你的父母&lt;/LinearLayout&gt; 就像下面的代码

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.shivamx.test_splash.Home_test"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@color/backgroundcolor">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_green"
                    android:padding="10dp"
                    android:src="@drawable/ic_inbox_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Engineering"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_yelow"
                    android:padding="10dp"
                    android:src="@drawable/ic_bba_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="BBA"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>





    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_pink"
                    android:padding="10dp"
                    android:src="@drawable/ic_bsc_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="BSc"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_bg_purple"
                    android:padding="10dp"
                    android:src="@drawable/ic_llb_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="LLB"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Study Material"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>






    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal">

        <android.support.v7.widget.CardView
            android:layout_width="150dp"
            android:layout_height="180dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circle_blue_aboutme"
                    android:padding="10dp"
                    android:src="@drawable/ic_about_me_box_black_24dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="About Me"
                    android:textStyle="bold" />

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_margin="10dp"
                    android:background="@color/lightgray">

                </View>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="About The Creator"
                    android:textColor="@color/darkgrey"

                    />

            </LinearLayout>


        </android.support.v7.widget.CardView>



    </LinearLayout>
</LinearLayout>

【讨论】:

    【解决方案3】:

    您没有在XML 中声明根layout element 或没有关闭根元素。所以你可能会出错。格式应如下所示。

    <rootelement>
       <subelement>
              .......
       </subelemnt>
    </rootelement>
    

    例如:

       <?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"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.divyesh.friendfinder.MainActivity"
        tools:showIn="@layout/app_bar_main">
    
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/Hint"
            android:inputType="text"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:id="@+id/editTextusername"
            android:layout_marginStart="10dp" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editTextusername"
            android:hint="Enter second user lat"
            android:inputType="text"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:id="@+id/editTextlat"
            android:layout_marginStart="10dp" />
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/editTextlat"
            android:hint="Enter second user long"
            android:inputType="text"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:id="@+id/editTextlong"
            android:layout_marginStart="10dp" />
        <TextView
            android:id="@+id/textinformssssss"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10sp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="Click Button bellow and Start Service"/>
    
        <Button
            android:id="@+id/subbutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:text="genrate location"
            android:layout_below="@+id/textinformssssss"/>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 2011-07-18
      • 1970-01-01
      相关资源
      最近更新 更多