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,
- Locate MainActivity Java or Kotlin file in Android Studio
- groovy.lang.MissingPropertyException No such property Error
- How to fix java.net.NoRouteToHostException in Android Studio
- Your Android SDK is missing, out of date or corrupted SDK Problem
- [Android Studio] MainActivity does not exist
- [Android Studio] Could not automatically detect an ADB binary
- Android Studio: Cannot perform refactoring operation
- How to Configure Eclipse keymap in IntelliJ IDE
- Android Studio setup was canceled - How to resume
- [Android Studio] Hardcoded string Button, should use @string resource
- The selected device is incompatible : Android Studio
- Android Activity Main xml stuck loading
- Android Studio 1.3 beta now Available for Developers
- Installing Android Studio Dolphin on Mac with Apple (M1/M2) Chip
- Android Studio 4.2 Canary 1 now available
- [Android Studio] Button on click example
- Eclipse like Auto Import Shortcut in Intelij IDE Android Studio
- How to enable line numbers in IntelliJ Android Studio for all files
- Delete Android Studio Projects
- How to update Android Studio
- [Android Studio] Error: Missing system image on device
- macOS Big Sur java.lang.UnsatisfiedLinkError CoreFoundation - Android Studio
- Android [SDK Manager] The system cannot find the path specified
- Failed to install Android.apk on device 'emulator-5554': timeout
- [Solved] Error launching studio
More Posts:
- Encode or Decode Base64 String using Mac Terminal Command - MacOS
- [Fix] Microsoft 53003 Error - Microsoft
- SwissCovid App Launched in Switzerland - News
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ - Java
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13 - MacOS
- Remove Html head and body tags from ckeditor source - Html
- GitHub: How to Search Code - Git
- java: unclosed string literal [Error] - Java