'Unable to find explicit activity class java

i am a new app developer i was working on a app for the past few days i have implemented onclicklistner in my program then the error shows like this.i have been working on a cardview project please help me from this and i am using new version of andriod. thank you

this is my Main activity:

package com.example.login;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import android.os.Handler;
import android.os.Handler;


public class MainActivity extends AppCompatActivity implements View.OnClickListener   {
 private static int SPLASH_SCREEN = 4000;
 private CardView d1,d2,d3,d4;

//varaibles

 Animation topAnim, bottomAnim;
 ImageView image;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     d1 = (CardView) findViewById(R.id.d1);
     d2 = (CardView) findViewById(R.id.d2);
     d3 = (CardView) findViewById(R.id.d3);
     d4 = (CardView) findViewById(R.id.d4);
    d1=null;
            d2=null;
                    d3=null;
                            d4=null;
     try {
         d1.setOnClickListener((OnClickListener) this);
         d2.setOnClickListener((OnClickListener) this);
         d3.setOnClickListener((OnClickListener) this);
         d4.setOnClickListener((OnClickListener) this);

     }catch (NullPointerException ignored){

     }

     //Animation
     topAnim = AnimationUtils.loadAnimation(this, R.anim.top_animation);
     bottomAnim = AnimationUtils.loadAnimation(this, R.anim.bottom_animation);

     //Hooks
     image = findViewById(R.id.imageView);
     image.setAnimation(topAnim);

     new Handler().postDelayed(new Runnable() {
         @Override
         public void run() {
             Intent intent = new Intent(MainActivity.this,dashboard2.class);
             startActivity(intent);
             finish();
         }
     }, SPLASH_SCREEN);


 }

 @Override
 public void onClick(View v){
     Intent i;
     switch (v.getId()){
         case R.id.d1: i = new Intent(this,d1.class); startActivity(i); break;
         case R.id.d2: i = new Intent(this,d2.class); startActivity(i); break;
         case R.id.d3: i = new Intent(this,d3.class); startActivity(i); break;
         case R.id.d4: i = new Intent(this,d4.class); startActivity(i); break;

     }


 }




}

this is my Manifest:

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

   <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.Login">
       <activity
           android:name=".d4"
           android:exported="false" />
       <activity
           android:name=".d3"
           android:exported="false" />
       <activity
           android:name=".d1"
           android:exported="false" />
       <activity
           android:name=".d2"
           android:exported="false" />
       <activity
           android:name=".MainActivity"
           android:exported="true">

           <intent-filter>
               <action android:name="android.intent.action.MAIN" />

               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>

</manifest>

this is my logcat:

  ```Process: com.example.login, PID: 16401
    android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.login/com.example.login.dashboard2}; have you declared this activity in your AndroidManifest.xml?
        at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1933)
        at android.app.Instrumentation.execStartActivity(Instrumentation.java:1616)
        at android.app.Activity.startActivityForResult(Activity.java:4487)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:597)
        at android.app.Activity.startActivityForResult(Activity.java:4445)
        at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:583)
        at android.app.Activity.startActivity(Activity.java:4806)
        at android.app.Activity.startActivity(Activity.java:4774)
        at com.example.login.MainActivity$1.run(MainActivity.java:61)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6494)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
    enter code here


Solution 1:[1]

Activity dashboard2 is not declared in your Manifest

Solution: Add below tag in your Manifest

 <activity
           android:name=".dashboard2"
           android:exported="false" />

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ammar Abdullah