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