[Android Studio] MainActivity does not exist

MainActivity does not exist or Error running 'app': Default Activity not found is an error you might get if you have either deleted or renamed the MainActivity.java file without refactoring the code.

If you do not find the file under app -> java directory then create a new one,


import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;

import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {
        Toolbar toolbar = findViewById(R.id.toolbar);

    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        return super.onOptionsItemSelected(item);

✌️ Few things you can try is checking undo list to see if the file was recently deleted to recover it, or if are using version control in your project you can recover it easily.

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap