当我启动我的应用程序时,它强制关闭,当我调试程序时,我不断收到错误消息。我有 2个活动,身份验证(用户登录)和主页(这是用户登录时的页面)。
这里的问题是,当我不登录时,我仍然可以登录。如果我已经登录,它应该带我去Mainpage(活动),但现在错误[< em>见下面]出现。
这来自堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blocktrekacademy.officialblocktrek/com.blocktrekacademy.officialblocktrek.Authentication}: android.content.ActivityNotFoundException: Unable to find explicit activity class {/com.blocktrekacademy.officialblocktrek.Mainpage}; have you declared this activity in your AndroidManifest.xml?
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {/com.blocktrekacademy.officialblocktrek.Mainpage}; have you declared this activity in your AndroidManifest.xml?
这是 AndroidManifest.xml 中的应用标记:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".Authentication"
android:label="@string/title_activity_authentication"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Mainpage"
android:label="@string/title_activity_mainpage"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"></activity>
</application>
注意:
我的类扩展了 AppCompatActivity
尝试过的解决方案:
我尝试在应用上添加android:name=".Authentication"
,但这给了我这个错误:
'com.blocktrekacademy.officialblocktrek.Authentication' is not assignable to 'android.app.Application'
AndroidManifest.xml 上的,以及 logcat 上的这些错误:
java.lang.RuntimeException: Unable to instantiate application com.blocktrekacademy.officialblocktrek.Authentication: java.lang.ClassCastException: com.blocktrekacademy.officialblocktrek.Authentication cannot be cast to android.app.Application
Caused by: java.lang.ClassCastException: com.blocktrekacademy.officialblocktrek.Authentication cannot be cast to android.app.Application
我真的是Android开发的新手:(
答案 0 :(得分:0)
如果你想从另一个具有明确意图的活动开始活动,这应该是这样的(你应该在检查登录凭证后执行以下操作):
Intent intent = new Intent(this, Mainpage.class);
startActivity(intent);
确保活动位于同一个包中或以其他方式调整MainActivity.class的路径,以便找到它。
答案 1 :(得分:0)
嗨@ user7994637尝试在AndroidManifest.xml中执行此操作
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".officialblocktrek.Authentication"
android:label="@string/title_activity_authentication"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".officialblocktrek.Mainpage"
android:label="@string/title_activity_mainpage"
android:theme="@style/AppTheme.NoActionBar"
android:screenOrientation="portrait"></activity>
</application>
我猜您的活动位于“officialblocktrek”包内,因此崩溃所以我更新了您的清单。希望它有所帮助。