0

I have already looking posts which talk about this error but nothing seems me false. I need your help because in a recycler view, I put this code to start a new activity when we click on an item. I have not finish but it doesn't work because of a :

    android.content.ActivityNotFoundException: Unable to find explicit activity class {fr.amseu.myapp/fr.amseu.myapp.Activity.LowerLegsActivity}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2069)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1717)
        at android.app.Activity.startActivityForResult(Activity.java:5250)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:676)
        at android.app.Activity.startActivityForResult(Activity.java:5208)
        at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:663)
        at android.app.Activity.startActivity(Activity.java:5579)
        at androidx.core.content.ContextCompat.startActivity(ContextCompat.java:251)
        at fr.amseu.mystretching.adapter.MuscleAdapter$onBindViewHolder$1.onClick(MuscleAdapter.kt:58)
        at android.view.View.performClick(View.java:7870)
        at android.view.View.performClickInternal(View.java:7839)
        at android.view.View.access$3600(View.java:886)
        at android.view.View$PerformClick.run(View.java:29363)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7948)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

And the app crash when we click on the correspondant button. Here is my setup for the button, and it works fine before I added this line :

override fun onBindViewHolder(holder: ViewHolder, position: Int)     {
holder.itemView.setOnClickListener{
            val onGroupClickListener = object  : OnGroupClickListener{}
            onGroupClickListener.onGroupItemClicked(position)

            if (position == 0) {
                CommentairePopup(this).show()
            } else if (position == 1) {
                
                //line which cause the problem
                val intent = Intent(context, LowerLegsActivity::class.java)
                startActivity(context, intent, null)
            } else if (position == 2) {
            } else if (position == 3) {
            } else if (position == 4) {
            } else if (position == 5) {
            } else if (position == 6) {
            }
        }
}

that is my manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="fr.amseu.mystretching">

    <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/Theme.MyStretching">
        <activity android:name=".activity.ChronometerActivity"/>
        <activity
            android:name=".lowerLegsActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_itam_exercices"
            android:theme="@style/Theme.MyStretching.Fullscreen"/>
        <activity
            android:name=".exercices"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_exercices"
            android:theme="@style/Theme.MyStretching.Fullscreen" />
        <activity
            android:name=".item_exercices"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/title_activity_itam_exercices"
            android:theme="@style/Theme.MyStretching.Fullscreen" />
        <activity android:name=".activity.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>


My activity is fine... If you have a clue of what can I review... If you need more informations, I am open ! Thanks for taking your time for this !

  • "...and my manifest too..." -- not according to the error message. Could you edit your question and post your manifest? – CommonsWare May 01 '21 at 19:15
  • Can you please share your manifest entry as well? – Navjot May 01 '21 at 19:24
  • it is done @CommonsWare – Amaury Seuriot May 01 '21 at 19:27
  • and @NavjotSinghBedi – Amaury Seuriot May 01 '21 at 19:27
  • Your `Intent` is for `fr.amseu.myapp.Activity.LowerLegsActivity`, in an application ID of `fr.amseu.myapp`. Your manifest entry appears to be for `fr.amseu.mystretching.LowerLegsActivity`. These do not match, and they need to. I recommend updating the `package` attribute in your manifest to match your application ID, and update the `android:name` of the `` to match where the activity class resides. – CommonsWare May 01 '21 at 19:33
  • @CommonsWare that was me who edit with a bad manifest, which correspond not with my app, my bad. But everything is fine, I just add Activity before `lowerLegsActivity` and it works ! – Amaury Seuriot May 02 '21 at 13:35

1 Answers1

1

What's Happening?

The activity lowerLegsActivity name seems incorrect in the manifest. Your application package name as per manifest is fr.amseu.mystretching, but the package in which your class LowerLegsActivity lies is different as per error logs i.e. fr.amseu.myapp.Activity

Solution 1 (Quick Fix)

Replace this

android:name=".lowerLegsActivity"

With

android:name="fr.amseu.myapp.Activity.LowerLegsActivity"

Solution 2 (Recommended)

Move class LowerLegsActivity to package fr.amseu.mystretching.Activity and perform the following replacement in the manifest

Replace this

android:name=".lowerLegsActivity"

With

android:name=".Activity.LowerLegsActivity"

Similar Issue: https://stackoverflow.com/a/10908567/1890849

Navjot
  • 1,202
  • 1
  • 11
  • 24