2012-07-26 130 views
3

我有Eclipse来生成一个基本的Android Hello World应用程序,但它有2个错误:首先,在我的AndroidManifest.xml中,这两行:
我得到根元素之后的文档中的标记必须格式良好,无论我多少次清理项目,我的R.java都不会生成。任何答案?AndroidManifest.xml根元素之后的文档中的标记必须格式良好

清单是在这里:http://jsfiddle.net/NHDU6/

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

    <uses-sdk 
     android:minSdkVersion="14" 
     android:targetSdkVersion="15" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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


<!-- 
    Declare the contents of this Android application. The namespace 
    attribute brings in the Android platform namespace, and the package 
    supplies a unique name for the application. When writing your 
    own application, the package name must be changed from "com.example.*" 
    to come from a domain that you own or have control over. 
--> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.jfkingsley.maclogin" > 

    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.GET_TASKS" /> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 
    <uses-permission android:name="android.permission.SET_WALLPAPER" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /> 

    <application 
     android:icon="@drawable/ic_launcher_home" 
     android:label="@string/home_title" > 
     <activity 
      android:name="Home" 
      android:launchMode="singleInstance" 
      android:stateNotNeeded="true" 
      android:theme="@style/Theme" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.HOME" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="Wallpaper" 
      android:icon="@drawable/bg_android_icon" 
      android:label="Wallpaper" > 
      <intent-filter> 
       <action android:name="android.intent.action.SET_WALLPAPER" /> 

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

</manifest> 

感谢,乔纳森

+3

发表您的清单 – 2012-07-26 11:37:08

+0

您是否删除了一个项目,然后创建了另一个具有相同名称的项目? – 2012-11-10 12:11:46

+0

不,问题是我有多个应用程序标记 – Excalibur 2012-11-10 14:04:56

回答

1

这是你的清单,

你不应该指定一个以上的Manifest,你不应该指定多个<application>标签。

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.jfkingsley.maclogin" > 

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

    <uses-permission android:name="android.permission.CALL_PHONE" /> 
    <uses-permission android:name="android.permission.GET_TASKS" /> 
    <uses-permission android:name="android.permission.READ_CONTACTS" /> 
    <uses-permission android:name="android.permission.SET_WALLPAPER" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" /> 

    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="h" > 
     <activity 
      android:name=".MainActivity" 
      android:label="@string/title_activity_main" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="Home" 
      android:launchMode="singleInstance" 
      android:stateNotNeeded="true" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.HOME" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="Wallpaper" 
      android:icon="@drawable/ic_launcher" 
      android:label="Wallpaper" > 
      <intent-filter> 
       <action android:name="android.intent.action.SET_WALLPAPER" /> 

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

</manifest> 
1

这可能是你失去了一些东西,但有时做一个简单的代码重新格式化:CTRL + SHIFT + F,清除问题。

+0

尝试过它,它不起作用 – Excalibur 2012-07-27 14:05:33

0

我看着你的清单文件。错误是由于您有两个声明<manifest />标记而引起的。

它始于:

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

然后一些评论是和另一个声明开始:

<!-- 
    Declare the contents of this Android application. The namespace 
    attribute brings in the Android platform namespace, and the package 
    supplies a unique name for the application. When writing your 
    own application, the package name must be changed from "com.example.*" 
    to come from a domain that you own or have control over. 
--> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.jfkingsley.maclogin" > 

    <uses-permission android:name="android.permission.CALL_PHONE" /> 

你要么忘了发表意见的清单标签之一,迷茫的东西,或者下面的错误教程。该AndroidManifest文件只能有一个<manifest />标签

+0

但如果我尝试删除其中一个标记,我得到另一个错误 – Excalibur 2012-07-27 16:12:15

0

自动生成的AndroidManifest.xml文件本身存在一些问题。里面有两个清单标签和两个使用sdk标签。那就是问题所在。别如下: 1-删除第一清单标签的结束标记是:所述第二清单标签的 </manifest> 2-删除定义标签,其是:

<manifest 
xmlns:android="http://schemas.android.com/apk/res/android" 
package="net.learn2develop.fragments" 
android:versionCode="1" 
android:versionName="1.0" > 

3-如果有两个用途-SDK标记,同时删除第二个uses-sdk标记。

-1

/>不应该在我有同样的问题,错误的文件结束意味着XML文件格式不正确,你应该尝试删除/在前面>或者干脆重新

+1

在文件末尾没有'/>'在问题中。你在说什么? – t0mppa 2013-12-31 23:50:10