尝试运行android教程表单时出现未定义的错误

Ste*_*hen 1 java android

我已经复制并粘贴了本网站上的Form stuff示例中的代码.当我尝试运行项目时,我收到一个错误,项目有一个带有白色十字的红色正方形但是当深入到项目的元素(使用eclipse)时,有一个错误的元素.在Eclipse的问题选项卡中,我有以下文字

描述资源路径位置类型Unparsed aapt错误!检查控制台输出.HelloFormStuff2未知的Android打包问题

但控制台里什么都没有!! 这是我正在使用的代码和元素......

HelloFormStuff2.java

package com.android.HelloLinearLayouts;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class HelloFormStuff2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        final Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Perform action on clicks
                Toast.makeText(HelloFormStuff2.this, 
                               "Beep Bop", 
                               Toast.LENGTH_SHORT).show();
            }
        });

    }


}

**res/drawable-hdpi/android-button.xml**
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/android_pressed"
          android:state_pressed="true"/>
    <item android:drawable="@drawable/android_focused"
          android:state_focused="true"/>
    <item android:drawable="@drawable/android_normal"/>
</selector>

**res/layout/main.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/hello"
    />
    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/android_button" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

kco*_*ock 6

不确定问题中的代码发生了什么,但检查res/layout /并确保没有main-out.xml.如果有,请删除它,执行"项目">"清理",然后通过右键单击项目并选择"运行方式">"Android应用程序"来运行该应用程序.

来自Visual Studio,我一直试图从任何地方做一个"run as",这在Eclipse中不起作用(除非我做错了其他事情); 相反,它试图运行xml文件,它始终给我这个错误.

如果我完全偏离基础,只需尝试Project> Clean ...,然后选择Project> Build All(如果它没有设置为自动).