解析XML时出错:找不到元素
首先请原谅我,如果我发布此问题错误。我用了很多问题的stackoverflow,但这是我第一次不能找到我的问题的答案。所以,如果我做错了,请让我知道,我会重新发布/编辑问题。解析XML时出错:找不到元素
现在营业。我刚刚开始使用Android SDK进行开发,我正在从基本教程http://developer.android.com/resources/tutorials/hello-world.html#avd 开始我已经完成了xml编辑部分,并且对xml文件main.xml和strings.xml进行了所有更改发生此错误。另外,当我编译项目时,编译过程会生成一个空的main.out.xml文件。我不知道它是什么或它的目的。
错误:
[2011-12-30 16:10:02 - Hello Razor] res\layout\main.xml:0: error: Resource entry main is already defined. [2011-12-30 16:10:02 - Hello Razor] res\layout\main.out.xml:0: Originally defined here. [2011-12-30 16:10:02 - Hello Razor] C:\Users\Dux69\workspace\Hello Razor\res\layout\main.out.xml:1: error: Error parsing XML: no element found [2011-12-30 16:10:13 - Hello Razor] Error in an XML file: aborting build.
我的项目是设置为平台:安卓2.3.3 API等级:10
我不知道这是否有差别或没有,但我使用我的Android Incredible用于运行/调试应用程序而不是Android虚拟设备。如果需要更多信息,请告诉我,我会尽快发布。
下面是我使用的三个代码文件:
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:text="@string/hello_O" />
的strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello_O">Baba in the house, Razor Activity!</string>
<string name="app_name">Hello Razor App</string>
</resources>
razorActivity.java
package hello.Razor;
import android.R;
import android.app.Activity;
import android.os.Bundle;
public class razorActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
我曾经有类似的问题。
重建/清理项目并重新启动Eclipse帮助了我。
删除main.out.xml在项目视图和重新运行的Android应用程序
错误消息我:
Error:(43) Error parsing XML: no element found
和
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException: Failed to execute aapt
解决方案:在我的情况下,项目activity_main.xml的启动代码为
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.batvibes.battybirthday.Main1Activity">
我忘记了下面的结束标记。
</android.support.constraint.ConstraintLayout>
声明:我对android开发完全陌生。我的建议,请检查所有的标签打开和关闭,并进入下一步调试。
如果不起作用,请删除main.out.xml并执行Clean,然后打开您的razorActivity.java并重新运行。这是一个常见的aapt错误 – 2011-12-30 23:49:29
哇感谢您的帮助。我必须经历一个关闭eclipse,重新打开它,删除该文件,然后清理的整个过程。真是个麻烦的人。无论如何,我可以解决这个问题吗? – DuxClarus 2011-12-31 02:36:39
当你第一次尝试“运行”你的应用程序时,你正在执行XML文件(从eclipse中我知道你很奇怪),所以当你运行应用程序时,它会一次又一次地启动XML文件,因为它是第一个你的历史运行..只需删除,打开你的razorActivity.java并从运行 - >运行历史启动,它应该终于永久固定 – 2011-12-31 09:45:17