2010-09-03 21 views
1

我已经复制并粘贴来自本网站上的Form stuff示例的代码。当我尝试运行该项目时出现错误,该项目有一个带有白色十字的小红色正方形,但是当向下钻入项目元素(使用eclipse)时,会出现错误元素。在eclipse的问题标签中,我有以下文本试图运行android教程时未定义的错误表格的东西

说明资源路径位置类型 未解析的aapt错误(s)!检查控制台的输出。 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> 

回答

6

不知道发生了什么事的问题你的代码,但在RES /布局检查/并确定没有main-out.xml。如果有,请删除它,执行Project> Clean,然后右键单击该项目并选择Run As> Android Application运行该应用程序。我一直试图从任何地方做一个“run as”,这在Eclipse中不起作用(除非我做了其他错误);相反,它试图运行xml文件,这一直给我提供了这个错误。

如果我完全不在基地,只需尝试Project> Clean ...,然后单击Project> Build All(如果未设置为自动)。

+0

工作正常!我干净了,不知道问题是什么,但它现在正在运行! :)谢谢你的帮助阿米戈! – Stephen 2010-09-05 10:27:13

+0

他应该接受你的答案! – 2011-01-12 18:10:12

1

在eclipse中,只需进入Project >> Clean,然后选择你想要的项目并打上干净的 ......就像魔术一样。

在我输入了一个没有真正扩展名的图像之后,发生了这种事......奇怪。

相关问题