Java Eclipse android 编程 XML 文件中的错误:中止构建
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9672672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
eclipse android programming Error in an XML file: aborting build
提问by Yagiz
i am creating an android application, a simple calculator, but i am getting an "[2012-03-12 20:22:21 - Calculator] Error in an XML file: aborting build." which i couldn't solve. could you identify the problem?
我正在创建一个 android 应用程序,一个简单的计算器,但我收到“[2012-03-12 20:22:21 - 计算器] XML 文件中的错误:中止构建。” 我无法解决。你能找出问题吗?
<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:
<?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>
采纳答案by Luksprog
If that is the entire xml layout then you must add on the first line this(before anything):
如果那是整个 xml 布局,那么你必须在第一行添加这个(在任何事情之前):
<?xml version="1.0" encoding="utf-8"?>
Also this:
还有这个:
xmlns:android="http://schemas.android.com/apk/res/android"
is only required only on the first element in the layout(in your case the LinearLayout
with the id linearLayout1
).
仅在布局中的第一个元素上需要(在您的情况下LinearLayout
为 id linearLayout1
)。
Edit:
编辑:
On your EditText
you set the color: android:textColor="@layout/main"
,this is wrong. If you want a color resource then do this:
在你的EditText
你设置颜色:android:textColor="@layout/main"
,这是错误的。如果您想要颜色资源,请执行以下操作:
android:textColor="@color/the_color"
where the_color
is a color set in your colors.xml
file in the values
folder containing:
在包含以下内容的文件夹the_color
中的colors.xml
文件中设置的颜色在哪里values
:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="the_color">#0077cc</color>
</resources>
回答by lee
It would appear that Eclipse is picky about the white space at the beginning of your XML files.
Eclipse 似乎对 XML 文件开头的空格很挑剔。
If you have the line in your file it must appear at the beginning of the file with no white space (space or tab) preceding it.
如果您的文件中有一行,它必须出现在文件的开头,并且前面没有空格(空格或制表符)。