代码之家  ›  专栏  ›  技术社区  ›  Shawn Mclean

第一个Android测试项目没有启动

  •  6
  • Shawn Mclean  · 技术社区  · 16 年前

    在我的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>
    

    My 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发布!
    2. [2010-02-02 01:46:26-SampleApp]亚洲开发银行运行正常。

    第3行和第4行以红色突出显示。

    是否有人能引导我的程序朝着正确的方向发展,让应用程序显示在模拟器上?

    带Eclipse的Android 2.1 SDK

    1 回复  |  直到 16 年前
        1
  •  11
  •   Mark B    16 年前

    您在应用程序中缺少以下内容: <activity>

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

    有关更多信息,请参阅 here