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,
package YOUR-PACKAGE;
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 {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
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.
More Posts related to Android-Studio,
- Step-by-Step: How to install Flutter in Android Studio
- [Android Studio] How to locate code for activity_main.xml
- [Event Log] Android Studio performance could be improved
- Android Studio emulator/Device logCat logs not displayed
- Show Android Studio Emulator in a Separate Window
- Android Studio SDK Build-tools 23 rc2 not getting installed
- Android Emulator Screenshot saved location
- [Android Studio] Error: Missing system image on device
- Android Studio NoClassDefFoundError: java.awt.Toolkit
- Android [SDK Manager] The system cannot find the path specified
- [Android Studio] Could not automatically detect an ADB binary
- Installing Android Studio Dolphin on Mac with Apple (M1/M2) Chip
- [Android Studio] MainActivity does not exist
- How to enable line numbers in IntelliJ Android Studio for all files
- Android Studio - Installed build tools revision 31.0.0 is corrupted. Remove and install again using the SDK manager.
- Android Studio setup was canceled - How to resume
- Your Android SDK is missing, out of date or corrupted SDK Problem
- Locate MainActivity Java or Kotlin file in Android Studio
- How to Determine Android Studio Gradle Version
- Delete Android Studio Projects
- [Android Studio] Button on click example
- Create assets folder in Android Studio
- Disabling Spell Check in Android Studio
- How to save IntelliJ IDE Console logs to external log file
- How to install Android Studio Chipmunk and SDK tools on macOS (2021.2)
More Posts:
- How to Center Align Image in Bootstrap - CSS
- Save TextEdit file as Microsoft Word File .docx extension - Microsoft
- Mac: Change Screenshot Location - MacOS
- Python: How to install psycopg2 using pip - PIP
- Java: Fix SAXParseException: :1:1: Content is not allowed in prolog. - Java
- [Solved] Error launching studio - Android-Studio
- How to Preview HTML, CSS, JavaScript in Notepad++ - NotepadPlusPlus
- Add imports in eclipse shortcut key combinations - Eclipse