anna
anna

Reputation: 433

android exception: activity not found

My application is crashing.
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.smartmedicineapplication/com.example.smartmedicineapplication.ProfActivity}; have you declared this activity in your AndroidManifest.xml?

Here is my manifest file:

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

    <application
        android:name=".app.App"
        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/AppTheme">
        <activity android:name="com.example.smartmedicineapplication.ProfActivity"/>
        <activity android:name=".CreateNotificationActivity" />
        <activity android:name=".MainScreenActivity" />
        <activity android:name=".ChangePasswordActivity" />
        <activity android:name=".SignUpActivity" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

And in my activity _ try make something like this:

  @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
        switch (menuItem.getItemId()) {
            case R.id.nav_share:
                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.nav_share_text));
                startActivity(Intent.createChooser(sharingIntent, getString(R.string.open_with)));
                break;
            case R.id.nav_settings:
                Intent intent = new Intent(this, ProfActivity.class);
                startActivity(intent);
                break;
        }
        return false;

And here is my Profile Activity:

package com.example.smartmedicineapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class ProfActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_prof);
    }
}

I have read same questions but nothing help me. I don't understand why it's happen.Please help me.

Upvotes: 0

Views: 62

Answers (2)

Manoj Perumarath
Manoj Perumarath

Reputation: 10194

Modify your manifest by removing the package path with

.

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

<application
    android:name=".app.App"
    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/AppTheme">
    <activity android:name=".CreateNotificationActivity" />
    <activity android:name=".MainScreenActivity" />
    <activity android:name=".ChangePasswordActivity" />
    <activity android:name=".SignUpActivity" />
    <activity android:name=".ProfActivity" />
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

Upvotes: 0

Salman
Salman

Reputation: 2471

Your manifest looks good. Just put the activity name in manifest with dot .ProfActivity and perform the below steps.

1- Carefully check your project structure

2- Try to create another test activity and replace with ProfActivity and check if it works

3- Clean your project and restart Android Studio

4- Before running your build again uninstall the previous build from your device

Upvotes: 1

Related Questions