Previously working activity now giving ActivityNotFoundException

I have a simple activity that was previously working and now fails and crashes my app with the below error. I haven't changed anything related to the activity, so I'm really not sure what is going wrong here. I've looked at similar questions but nothing they've suggested has worked.

Any ideas would be greatly appreciated.

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)

The activity is called like this

 Target.setOnClickListener {
        val intent = Intent(this, Target::class.java)
        startActivity(intent)
    }

and my AndroidManifest.xml looks like this

<?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>

2 answers

  • answered 2018-05-16 05:36 Manish Gupta

    You forgot to declare your activity. Write this in your manifest under application tag:

    <activity android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden"
        android:name=".FragmentActivity" />
    

  • answered 2018-05-17 01:15 hmadland

    I fixed the issue by replacing

    Target.setOnClickListener{
                val intent = Intent(this, Target::class.java)
                  intent.putExtra("PlayerID", PlayerID)
                startActivity(intent)
            }
    

    with this

    Target.setOnClickListener{
                val intent = Intent(this, com.hmadland.paranoia.Target::class.java)
                  intent.putExtra("PlayerID", PlayerID)
                startActivity(intent)
            }
    

    Not quite sure why, but might have been a naming issue with the button being called Target and activity Target.