Reputation: 3795
I've struggled with this for two days now.No matter what I do, Android Studio 2.1.1 , running on windows 10 64 keeps throwing
Could not identify launch activity: Default Activity not found Error while Launching activity .
Also, syntax highlighting for java files isn't working either, i.e. my MainActivity.java file has no syntax checking at all.
I've had no luck with any SO answers which mainly included one or more of the below:
I've tried
1- Invalidating caches and restarting android studio
2- Cleaning/Rebuilding
3- Restarting windows
4- Completely removing android studio and reinstalling from scratch
5- Gradle resync
6- Trying to create new projects with varying SDKs just to get atleast one to build- none does
Any ideas why this is happening? For reference , my files are below
MainActivity.java:
package com.example.simpleapp.simpleapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml ( the .MainActivity is in red, it can't find that either)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simpleapp.simpleapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<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>
Gradle Project File
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle Module file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.simpleapp.simpleapp"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
}
Thanks
Upvotes: 1
Views: 6712
Reputation: 1459
The problem could be in the Manifest file. In my case, I did some refactoring that affected the 'activity' tags, (after changing a variable 'activity' into 'mActivity'), that's why it could not find the launcher Activity.
Upvotes: 0
Reputation: 27
My problem was MainActivity.java
not identifying as class.
I went to File -> Settings -> Editor -> FileTypes and removed "MainActivity.java" in the right hand pane under "Recognized File Types".
in my case it was in txt file types.
Upvotes: 0
Reputation: 3795
OK after many frustrating hours, I discovered that somehow "MainActivity.java"
got added as a recognized file type. No idea how, but as the default name for all activities added with Add->New Activity
wizard is "MainActivity"
, android studio always treated "MainActivity.java"
as jsp. So every time I added a new activity , it could never find the main activity!
I went to File -> Settings -> Editor -> FileTypes and removed "MainActivity.java" in the right hand pane under "Recognized File Types".
This fixed the problem. Hope it helps someone else.
Upvotes: 1
Reputation: 391
Give total path of your .MainActivity in Manifest.xml file
<activity android:name="com.example.simpleapp.simpleapp.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
This based upon:-
Default launcher activity defined here and that will be pointing to android:name tag where MainActivty exist.When ever activity tad does n't found in manifest it will through "Could not identify launch activity: Default Activity not found Error while Launching activity" .User might be changed the package in middle will cause this issue
Upvotes: 1