3

I've tried to re-create my project cause of this error, in emulator the error was solved, but it kept on android device. It is saying that my MainActivity does not exist.

I saw this question and tried all answers, but all failed.

Error while executing: am start -n "com.example.test/com.example.myapplication.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.test/com.example.myapplication.MainActivity }
Error type 3
Error: Activity class {com.example.test/com.example.myapplication.MainActivity} does not exist.

Error while Launching activity

Here is my AndroidManifest.xml:

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <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/AppTheme">
        <activity
            android:name="com.example.myapplication.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

This is my MainActivity, basically the Navigation Drawer template from android studio:

package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.Menu
import com.google.android.material.navigation.NavigationView
import androidx.navigation.findNavController
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import androidx.drawerlayout.widget.DrawerLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar

class MainActivity : AppCompatActivity() {

    private lateinit var appBarConfiguration: AppBarConfiguration

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val toolbar: Toolbar = findViewById(R.id.toolbar)
        setSupportActionBar(toolbar)

        val drawerLayout: DrawerLayout = findViewById(R.id.drawer_layout)
        val navView: NavigationView = findViewById(R.id.nav_view)
        val navController = findNavController(R.id.nav_host_fragment)
        appBarConfiguration = AppBarConfiguration(setOf(
            R.id.nav_home), drawerLayout)
        setupActionBarWithNavController(navController, appBarConfiguration)
        navView.setupWithNavController(navController)
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.main, menu)
        return true
    }

    override fun onSupportNavigateUp(): Boolean {
        val navController = findNavController(R.id.nav_host_fragment)
        return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
    }
}
0

2 Answers 2

11

It happened after I uninstalled the app directly from android device. To solve it, I ran:

adb devices -- to get the connected devices list

followed by:

adb -s device android id uninstall package.name

Then, I ran again in android device with success

Edit: to clarify the bold texts:

device android id is one of id you'll get after type adb devices. Typing it, you'll get a list of connected devices with the ids

package.name is the text on top of your kotlin/java files, after the "package", like com.yourname.appname

Sign up to request clarification or add additional context in comments.

3 Comments

This worked for me the bold type needs explanation - -- 'device android id' is the device name that you get when you run the adb devices command -- 'package name' is the top line of your MainActivity.java file - like - com.yourname.appname
@jday I edited my answer to explain about, thanks for feedback!
When i tried this, i got this error Failure [DELETE_FAILED_INTERNAL_ERROR]
0

Error: Activity class {com.example.test/com.example.myapplication.MainActivity} does not exist.

Use this in your AndroidManifest.xml:

<activity
   android:name=".MainActivity"
   android:label="@string/app_name"
   android:theme="@style/AppTheme.NoActionBar">

1 Comment

Where is your MainActivity located? Any screenshots to see? I've just created a project (Navigation Drawer template) and it seems to be working fine with android:name=".MainActivity". Still need to check if your MainActivity exist in the com.example.test package or not. You were also giving the IDE the path to find MainActivity from this package: com.example.myapplication which your package name is: com.example.test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.