繁体   English   中英

eclipse android编程XML文件中的错误:中止构建

[英]eclipse android programming Error in an XML file: aborting build

我正在创建一个Android应用程序,一个简单的计算器,但我得到一个XML文件中的“[2012-03-12 20:22:21 - 计算器]错误:中止构建。” 这是我无法解决的。 你能找出问题吗?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<LinearLayout 
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<EditText
    android:id="@+id/txtResult"
    android:layout_width="fill_parent"
    android:layout_height="54dp"
    android:inputType="number"
    android:singleLine="true"
    android:text="@string/result"
    android:editable="false" 
    android:gravity="right">
</EditText>

</LinearLayout>
<LinearLayout 
android:id="@+id/linearLayout3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

 <Button
     android:id="@+id/button1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1.25"
     android:text="@string/number1" />

 <Button
     android:id="@+id/button2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1.25"
     android:text="@string/number2" />

 <Button
     android:id="@+id/button3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:text="@string/number3"
     android:layout_weight="1.25" />

 <Button
     android:id="@+id/buttonPlus"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_weight="1.25"
     android:text="@string/calcAddition" />

</LinearLayout>
 <LinearLayout 
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

     <Button
         android:id="@+id/button4"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number4"
         android:layout_weight="1.25" />

     <Button
         android:id="@+id/button5"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number5" 
         android:layout_weight="1.25"/>

     <Button
         android:id="@+id/button6"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number6"
         android:layout_weight="1.25"/>

     <Button
         android:id="@+id/buttonMinus"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1.25"
         android:text="@string/calcMinus" />

</LinearLayout>
 <LinearLayout 
android:id="@+id/linearLayout5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

     <Button
         android:id="@+id/button7"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number7"
         android:layout_weight="1.25" />

     <Button
         android:id="@+id/button8"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number8" 
         android:layout_weight="1.25"/>

     <Button
         android:id="@+id/button9"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/number9" 
         android:layout_weight="1.25"/>

     <Button
         android:id="@+id/buttonMultiplication"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1.25"
         android:text="@string/calcMultiplication" />

</LinearLayout>
<LinearLayout 
android:id="@+id/linearLayout6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

     <Button
         android:id="@+id/button0"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1.02"
         android:text="@string/number0" />

     <Button
         android:id="@+id/buttonCLR"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="0.67"
         android:text="@string/calcCLR" />

     <Button
         android:id="@+id/btnCalcEqual"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="@string/calcEqual" />

     <Button
         android:id="@+id/buttonDivision"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1.1"
         android:text="@string/calcDiv" />

</LinearLayout>


</LinearLayout>

strings.xml中:

<?xml version="1.0" encoding="utf-8"?>

<string name="app_name">Calculator</string>
<string name="number1">1</string>
<string name="number2">2</string>
<string name="number3">3</string>
<string name="number4">4</string>
<string name="number5">5</string>
<string name="number6">6</string>
<string name="number7">7</string>
<string name="number8">8</string>
<string name="number9">9</string>
<string name="number0">0</string>
<string name="calcCLR">CLR</string>
<string name="calcDiv">/</string>
<string name="calcMultiplication">*</string>
<string name="calcAddition">+</string>
<string name="calcMinus">-</string>
<string name="result">0</string>
<string name="calcEqual">Calculate</string>

</resources>

如果这是整个xml布局,那么你必须在第一行添加(在任何事情之前):

<?xml version="1.0" encoding="utf-8"?>

这个:

xmlns:android="http://schemas.android.com/apk/res/android"

仅在布局中的第一个元素上才需要(在您的情况下, LinearLayout的id为linearLayout1 )。

编辑:

在你的EditText设置颜色: android:textColor="@layout/main" ,这是错误的。 如果你想要一个颜色资源,那么这样做:

android:textColor="@color/the_color"

其中the_colorvalues文件夹中包含以下values colors.xml文件中的颜色集:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="the_color">#0077cc</color>

</resources>

看起来Eclipse对XML文件开头的空白区域很挑剔。

如果文件中有行,则它必须出现在文件的开头,前面没有空格(空格或制表符)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM