我遇到了同样的问题,并通过编辑文件 AndroidManifest.xml 并将行移动<?xml version="1.0" encoding="utf-8"?>
到 copywrite 注释上方来解决它:
<!--
Copyright (C) 2012 The Android Open Source Project
似乎解析器需要读取<?xml
文件开头的标签。我在这里提交了错误报告:http ://code.google.com/p/android/issues/detail?id=30505&thanks=30505&ts=1336503159
总之,您的 AndroidManifest.xml 文件应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2012 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.fragments"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".MainActivity"
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>
导入项目后,您必须在项目中的其他 xml 文件(res/layout/article_view.xml、res/layout/news_articles.xml、res/layout-large/news_articles.xml、和 res/values/strings.xml)。
我发现eclipse在src/目录下创建的包叫com.example.fragments而不是com.examples.android.fragments。我不知道为什么会发生这种情况,但我通过单击每个文件的包声明处的错误消息并选择:将“FILENAME.java”移动到包“com.example.android.fragments”来修复它。
最后,我必须在 HeadlinesFragment.java 中导入 android.os.Build 才能编译和运行项目。