gpt4 book ai didi

android - 找不到 Activity 异常

转载 作者:行者123 更新时间:2023-11-29 14:31:06 25 4
gpt4 key购买 nike

  • 我收到 activityNotFound 异常。无法找到显式 Activity 类。但是我已经在 list 中声明了我的 Activity 。

  • 我搜索了很多关于这个问题的 SO 帖子。但它没有解决了我的问题。

堆栈跟踪:

07-06 23:52:27.226: E/AndroidRuntime(7600): FATAL EXCEPTION: main
07-06 23:52:27.226: E/AndroidRuntime(7600): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.stevedata/android.app.ListActivity}; have you declared this activity in your AndroidManifest.xml?
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Activity.startActivityForResult(Activity.java:3390)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Activity.startActivityForResult(Activity.java:3351)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Activity.startActivity(Activity.java:3587)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.Activity.startActivity(Activity.java:3555)
07-06 23:52:27.226: E/AndroidRuntime(7600): at com.example.stevedata.MainActivity$1.onClick(MainActivity.java:38)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.view.View.performClick(View.java:4240)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.view.View$PerformClick.run(View.java:17721)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.os.Handler.handleCallback(Handler.java:730)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.os.Looper.loop(Looper.java:137)
07-06 23:52:27.226: E/AndroidRuntime(7600): at android.app.ActivityThread.main(ActivityThread.java:5103)
07-06 23:52:27.226: E/AndroidRuntime(7600): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 23:52:27.226: E/AndroidRuntime(7600): at java.lang.reflect.Method.invoke(Method.java:525)
07-06 23:52:27.226: E/AndroidRuntime(7600): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
07-06 23:52:27.226: E/AndroidRuntime(7600): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-06 23:52:27.226: E/AndroidRuntime(7600): at dalvik.system.NativeStart.main(Native Method)

MainActivity.java

public class MainActivity extends Activity {


Button button1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

button1=(Button)findViewById(R.id.button1);

button1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

Intent intent=new Intent(MainActivity.this,ListActivity.class);

startActivity(intent);

}
});

}

}

ListActivity.java:

public class ListActivity extends Activity {

Button button1;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_activity);

button1=(Button)findViewById(R.id.button);
}
}

list :

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity
android:name=".ListActivity"
android:label="@string/app_name"
/>

</application>

任何人都可以帮助我。谢谢。

最佳答案

看起来您在 MainActivity 中导入了错误的 ListActivity。崩溃表明您正在尝试启动 android.app.ListActivity

关于android - 找不到 Activity 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31259761/

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