gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:38:51 27 4
gpt4 key购买 nike

我正在创建我的第一个 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 > 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" 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 发布!
  2. [2010-02-02 01:46:26 - SampleApp]adb 运行正常。
  3. [2010-02-02 01:46:26 - SampleApp]未找到启动器 Activity !
  4. [2010-02-02 01:46:26 - SampleApp]启动只会同步设备上的应用程序包!
  5. [2010-02-02 01:46:26 - SampleApp]执行同步

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

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

带有 Eclipse 的 Android 2.1 SDK

最佳答案

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

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

有关详细信息,请参阅 here

关于android - 第一个 Android 测试项目没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2186758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com