第一个Android测试项目无法启动

时间:2010-02-02 18:58:13

标签: android

我正在创建我的第一个Android应用程序,但它根本没有启动。

在我的src> android.SampleApp我用:

创建了一个名为Main.java的java文件
public class Main extends Activity {

// Will be connected with the buttons via XML
public void myClickHandler(View view) {
    switch (view.getId()) {
    case R.id.btn1:
        ((EditText) findViewById(R.id.txtContent)).setText("Button 1 Clicked");
        break;
    case R.id.btn2:
        ((EditText) findViewById(R.id.txtContent)).setText("Button 2 Clicked");
        break;

    }
}
}

在我的res>布局> 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" android:id="@+id/txtContent"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button One" android:id="@+id/btn1"></Button>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button Two" android:id="@+id/btn2"></Button>

我的AndroidManifest.xml内容:

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="android.SampleApp"
  android:versionCode="1"
  android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">


</application>
<uses-sdk android:minSdkVersion="7" />

我收到此错误:

  1. [2010-02-02 01:46:26 - SampleApp] Android Launch!
  2. [2010-02-02 01:46:26 - SampleApp] adb正常运行。
  3. [2010-02-02 01:46:26 - SampleApp]未找到Launcher活动!
  4. [2010-02-02 01:46:26 - SampleApp]启动只会同步设备上的应用程序包!
  5. [2010-02-02 01:46:26 - SampleApp]执行同步
  6. 第3行和第4行以红色突出显示。

    有人可以引导我朝着正确的方向前进,让应用程序在模拟器上显示吗?

    使用Eclipse的Android 2.1 SDK

1 个答案:

答案 0 :(得分:11)

您在清单文件的<activity>标记中缺少以下内容:

        <intent-filter . . . >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

有关详细信息,请参阅here