元素类型“应用程序”必须后跟属性规范,“>”或“/>”

时间:2013-06-19 21:29:58

标签: android styles themes manifest

我的代码遇到了一些问题。

顺便说一句,我正在从newboston那里学习,目前正在学习11,我在做教程10时遇到了这个错误,我不打算继续学习下一个教程,直到修复完毕。

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thenewboston.sammy"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"

它说: 元素类型“应用程序”必须后跟属性规范,“&gt;”或“/&gt;”。

        <activity android:name="com.thenewboston.sammy.StartingPoint"
            android:label="@string/app_name" 
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

4 个答案:

答案 0 :(得分:3)

您不能在字符串资源中拥有空格。我会将@string/Your total is 0更改为@string/total_is_zero,然后在strings.xml中创建该字符串资源:

res/values/strings.xml创建:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="total_is_zero">Your total is 0</string>
</resources>

答案 1 :(得分:0)

如果你正在使用@string,那么Eclipse希望找到一个名为“你的总数为0”的资源 strings.xml文件。例如,你可以创建一个名为total的字符串并定义它的

<string name="total">Your total is 0</string>

然后,您将在xml中将其引用为

<android:text= "@string/total">

如果您只想显示文字,可以用

替换textview字段
<android:text= "Your total is 0">

希望这很清楚

答案 2 :(得分:0)

我强烈要求您阅读this article,并尝试了解资源在Android中的运作方式。

如果要添加字符串资源,则需要创建string.xml文件并将其放入res / values /目录。 在该文件中,请遵循以下格式:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello!</string>
    <string name="total_is_zero">Your total is 0</string>
</resources>

然后,您可以通过

将所需的字符串资源分配给xml中的元素
<TextView
    android:layout_width= "fill_parent"
    android:layout_height= "wrap_content"
    android:text="@string/total_is_zero"
    android:textSize="45sp"
    android:layout_gravity="center"
    android:gravity="center"
    android:id="@+id/tvDisplay"
    />

答案 3 :(得分:0)

试试这个并告诉我们结果:

从布局文件中删除此

<resources>
    <string name="total_is_zero"> Total is zero</string>
</resources>
<resources> 
    <string name="add_one"> Add one</string>
</resources>
<resources>
    <string name="subtract_one"> Subtract one</string>
</resources>

并将其移动到一个文件res / values / strings.xml中,如

   <?xml version= "1.0" encoding= "utf-8"?>
   <resources>
        <string name="total_is_zero"> Total is zero</string>
        <string name="add_one"> Add one</string>
        <string name="subtract_one"> Subtract one</string>
    </resources>

res / layout / activity_starting_point.xml文件看起来应该是

<?xml version= "1.0" encoding= "utf-8"?>
<LinearLayout 
    xmlns:android= "http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width= "fill_parent"
    android:layout_height= "fill_parent"
    >
    <TextView
        android:layout_width= "fill_parent"
        android:layout_height= "wrap_content"
        android:text="@string/total_is_zero"
        android:textSize="45sp"
        android:layout_gravity="center"
        android:gravity="center"
        android:id="@+id/tvDisplay"
        />

       <Button 
           android:layout_width="250dp" 
           android:layout_height="wrap_content"
           android:text="@string/add_one"
           android:layout_gravity="center"
           android:textSize="20sp"
           android:id="@+id/bAdd"
           />
        <Button 
           android:layout_width="250dp" 
           android:layout_height="wrap_content"
           android:text="@string/subtract_one"
           android:layout_gravity="center"
           android:textSize="20sp"
           android:id="@+id/bSubtract"
           />
</LinearLayout>
相关问题