gpt4 book ai didi

android.content.ActivityNotFoundException : Unable to find explicit activity class - how to fix it?

转载 作者:太空狗 更新时间:2023-10-29 15:51:13 29 4
gpt4 key购买 nike

我有一个非常基本但烦人的问题。我创建了新的 Activity 并将移动的 Intent 传递给它们。然而,当我传达两者时:MainMenu 和 EventCreationActivity,我收到以下错误:

android.content.ActivityNotFoundException:无法找到明确的 Activity 类{/com.mysampleapp.EventCreationActivity};您是否已在 AndroidManifest.xml 中声明此 Activity ?

当我单独运行这些 Activity 时,它们运行良好。这是主菜单的代码

   package com.mysampleapp;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

//import com.amazon.mysampleapp.R;

public class MainMenu extends AppCompatActivity {
//public final static String EXTRA_MESSAGE = "com.mysampleapp.MESSAGE";
final Intent intent = new Intent(this, EventCreationActivity.class);
Button newEvent;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

newEvent = (Button) findViewById(R.id.new_event_button);

newEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(intent);
}
});

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}



}

和 list :

   <application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".SplashActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
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=".MainActivity"
android:label="@string/title_activity_main" />
<activity
android:name=".LogInActivity"
android:label="@string/title_activity_log_in"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainMenu"
android:label="@string/title_activity_main_menu"

android:theme="@style/AppTheme">
<!--android:parentActivityName=".LogInActivity"-->
<!--<meta-data-->
<!--android:name="android.support.PARENT_ACTIVITY"-->
<!--android:value="com.mysampleapp.LogInActivity" />-->
</activity>
<activity
android:name=".MainDrawerActivity"
android:label="@string/title_activity_main_drawer"
android:theme="@style/AppTheme">
<!--<meta-data-->
<!--android:name="android.support.PARENT_ACTIVITY"-->
<!--android:value="com.mysampleapp.MainMenu" />-->
</activity>
<activity
android:name=".EventCreationActivity"
android:label="@string/title_activity_event_creation"

android:theme="@style/AppTheme">
<!--android:parentActivityName=".MainMenu"-->
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--</intent-filter>-->
<!--<meta-data-->
<!--android:name="android.support.PARENT_ACTIVITY"-->
<!--android:value="com.mysampleapp.MainMenu" />-->
</activity>

如您所见,我在 Manifest 文件中注释了一些内容,但没有帮助。我还查看了其他类似的问题,但没有帮助。

提前致谢,约翰

最佳答案

解决方案在你的问题中

have you declared this activity in your AndroidManifest.xml?

在您的 Manifest 中使用类的完整包名

android:name="com.mysampleapp.MainMenu"

关于android.content.ActivityNotFoundException : Unable to find explicit activity class - how to fix it?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37731315/

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