xml中的Premature end of file

  写Android的时候想自己写个布局文件,索性就准备把自己生成的给全部注释掉,代码如下:

<!--  
<RelativeLayout 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: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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>
-->

  结果第一行就有一个让程序员恐惧的一个东西:红叉。。。。

  如果把光标移动红叉上面就提示Premature end of file.

  而且控制台会输出:Error in an XML file: aborting build.

  上网百度了一下,发现没有找到我想要的答案,于是自己就开始乱捣鼓,结果还居然可以了,虽然不明觉厉

  其实我只是简单地修改一下而已

<RelativeLayout 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: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" >
<!--  
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
-->
</RelativeLayout>
 

  对比了一下两者的区别,发现不同的是标签的包含范围,前者是<!-- -->中包含了全部,后者是<!-- -->包含了部分。

  所以个人由此YY一个结论:<!-- -->的开始部分<!-- 不能放于文件的开头。

  刚才再次测试了一下,发现如果<!-- -->的前面仅仅是<?xml version="1.0" encoding="utf-8"?>,那么也会报相同的错误。

  有了这个YY, 验证起来也就简单多了,所以也算是解决了。


转载请注明原文地址,谢谢~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值