我有一个以前工作过的简单活动,但现在失败并且因以下错误导致我的应用崩溃。我没有改变与活动有关的任何事情,所以我真的不确定这里出了什么问题。我看过类似的问题,但他们建议没有任何效果。
非常感谢任何想法。
05-15 22:13:31.381 14563-14563/com.hmadland.paranoia E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.hmadland.paranoia, PID: 14563
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.hmadland.paranoia/android.support.v7.widget.AppCompatButton}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
at android.app.Activity.startActivityForResult(Activity.java:3968)
at android.support.v4.app.BaseFragmentActivityApi16.startActivityForResult(BaseFragmentActivityApi16.java:54)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:68)
at android.app.Activity.startActivityForResult(Activity.java:3920)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:751)
at android.app.Activity.startActivity(Activity.java:4259)
at android.app.Activity.startActivity(Activity.java:4227)
at com.hmadland.paranoia.Profile$onCreate$2.onClick(Profile.kt:91)
at android.view.View.performClick(View.java:5265)
at android.view.View$PerformClick.run(View.java:21534)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5765)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
活动就像这样调用
Target.setOnClickListener {
val intent = Intent(this, Target::class.java)
startActivity(intent)
}
我的AndroidManifest.xml看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET"/>
//camera access stuff
<uses-feature android:name="android.hardware.camera2" android:required="true"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".Register" />
<activity android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".Login" />
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".Profile" />
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".Target" />
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".Inventory" />
<activity
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".UpcomingGames">
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.android.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
答案 0 :(得分:0)
您忘了宣布您的活动。在应用程序标记下的清单中写下这个:
<activity android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:name=".FragmentActivity" />
答案 1 :(得分:0)
我通过替换
解决了这个问题Target.setOnClickListener{
val intent = Intent(this, Target::class.java)
intent.putExtra("PlayerID", PlayerID)
startActivity(intent)
}
用这个
Target.setOnClickListener{
val intent = Intent(this, com.hmadland.paranoia.Target::class.java)
intent.putExtra("PlayerID", PlayerID)
startActivity(intent)
}
不太确定原因,但可能是按钮被称为目标和活动目标的命名问题。