Ambrish
Ambrish

Reputation: 1

how to fix error in context.startActivity(intent)?

my app crashes when i click and the logcat points me to this line mentioned below.

public void onClick(View v) {
                Intent intent = new Intent(mContext, Recipe.class)

                intent.putExtra("Name",mData.get(i).getRecipeName());
                intent.putExtra("Description",mData.get(i).getRecipeDescription());
                intent.putExtra("Duration",mData.get(i).getRecipeDuration());
                intent.putExtra("Method", mData.get(i).getRecipeMethod());
                intent.putExtra("Ingredients", mData.get(i).getRecipeIngredients());

                mContext.startActivity(intent);//error in this line

            }

These are the error I see in logcat.

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.assignment1mypageambrish/com.example.assignment1mypageambrish.Recipe}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2065)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1727)
        at android.app.Activity.startActivityForResult(Activity.java:5320)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
        at android.app.Activity.startActivityForResult(Activity.java:5278)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
        at android.app.Activity.startActivity(Activity.java:5664)
        at android.app.Activity.startActivity(Activity.java:5617)
        at com.example.assignment1mypageambrish.RecyclerViewAdapter$1.onClick(RecyclerViewAdapter.java:68)
        at android.view.View.performClick(View.java:7448)
        at android.view.View.performClickInternal(View.java:7425)
        at android.view.View.access$3600(View.java:810)
        at android.view.View$PerformClick.run(View.java:28305)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

How do I fix this?

Upvotes: 0

Views: 92

Answers (1)

Prakash Niraula
Prakash Niraula

Reputation: 56

Check if your Activity is listed in your Android Manifest File. IF not so add

activity android:name=".view_controller.Home"

activity like this then you would be able to navigate from one activity to another.

Upvotes: 1

Related Questions