92

I just upgraded to Android Studio 0.2.8 and I am getting an error that says "Default Activity not found" when I try to edit the run configurations.

When I launch Android Studio I get this error "Access is allowed from event dispatch thread only"

The activity I am using is a fragment activity.

So far I've tried rebuilding and invalidate caches/restart. Both were of no use.

Please let me know what I can do to fix the problem.

Vipassana Vijayarangan
  • 8,799
  • 2
  • 17
  • 20
  • Possible duplicate of [Error: Default Activity Not Found](http://stackoverflow.com/questions/15825081/error-default-activity-not-found) – Sky Kelsey May 10 '16 at 18:40

29 Answers29

51

Have you added ACTION_MAIN intent filter to your main activity? If you don't add this, then android won't know which activity to launch as the main activity.

ex:

<intent-filter>
      <action android:name="android.intent.action.MAIN"/>
      <action android:name="com.package.name.MyActivity"/>
      <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Anup Cowkur
  • 20,443
  • 6
  • 51
  • 84
  • 1
    Yes, this is done. I fixed the "Access is allowed from the event dispatch thread only" by using oracle JDK instead of openJDK. The default activity missing still persists though – Vipassana Vijayarangan Sep 17 '13 at 09:38
  • 5
    Also the name `"com.package.name.MyActivity"` could be ommitted if all the `` element is inside an `` element that corresponds to your MyActivity in your namespace. – Xavi Montero Nov 21 '14 at 18:35
  • Hah, I renamed a class named `Filter` including all variables named `filter` and apparently Android Studio decided to include `AndroidManifest.xml` and ``. This answer made my double check my `AndroidManifest.xml` and helped me find the bug =) – Stephan Henningsen Sep 20 '16 at 21:41
  • Where is this even documented? I can’t find it… – mirabilos Aug 14 '20 at 23:28
45

In Android Studio, right click on the project and choose Open Module Settings. Then go to the Sources tab in your module, find the src folder, right click on it and mark it as Sources (blue color).

EDIT: There is no sources tab in later versions of Android Studio, but you can edit the build.gradle file instead: https://stackoverflow.com/a/22028681/1101730 (thanks for comment Josh)

Community
  • 1
  • 1
Micer
  • 8,731
  • 3
  • 79
  • 73
  • 27
    How could I do this in *0.6.1*? I don't see a **Sources** tab. – lschlessinger Jun 27 '14 at 00:03
  • 7
    me neither. There are Properties, Signing, Flavors, Build Types and Dependencies – Junior Mayhé Jun 28 '14 at 00:41
  • 4
    I had no "Sources" tab, so I edited the build.gradle file instead: http://stackoverflow.com/a/22028681 – Josh Nov 10 '14 at 20:57
  • 2
    Perfect! Thanks for helping @Micer. Guys, in your IntelliJ project press 'F4', then you have three tabs (Sources, Paths, Dependencies), go to 'Sources' tab and check if the 'src' folder (in the tree structure) it's blue. If not press 'Alt+S' to include the source folder in the Project Structure. – Ryan Amaral Nov 14 '14 at 01:47
  • @Micer There is no Sources tab. – IgorGanapolsky Jan 05 '15 at 15:18
  • 1
    @IgorGanapolsky You're right, seems like Sources tab has been removed in later versions of Android Studio. Check Josh's answer. – Micer Jan 08 '15 at 14:40
  • 1
    I had same problem. I just restarted the android studio and it was fine. Not a logical answer but solved my problem. – user1154390 Sep 18 '15 at 09:26
  • 1
    this has moved in Android Studio 1.5.1 it as at File -> Project Structure... -> Modules -> Sources – Mark Ch Jan 26 '16 at 11:24
  • 1
    In Android Studio 2.2, the fix is slightly different. For an activity that actually does not have an activity that launches at startup, like a background app. It can be fixed by pull-down menu for the packages, then Edit Configurations > choose your package on the left > under General tab > Launch Options > Launch > Nothing – nevzo Sep 22 '16 at 21:15
33

I had the same problem while importing a project into Android Studio, probably caused by the fact that the project has been developed on an earlier version of Android Studio than currently installed on my computer.

What solved it was simply choosing:

File -> Invalidate Caches / Restart...

and then selecting Invalidate and Restart.

syntagma
  • 23,346
  • 16
  • 78
  • 134
  • 1
    Thank you very much @syntagma, your guidance solved my problem after hours of effort. – MMG Mar 11 '20 at 05:45
17

If you don't have the tab and you started with an empty activity try this. Below is a sample code example:

<application android:label="@string/app_name">

    <activity android:name=".HelloActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

</application>

Now go to your AndroidManifest.xml file. Next copy the intent filter from this code. Look at your manifest file really good and paste the intent filter in the exact place it is in the code above. (after the .yourActivityName> part of the manifest.) I hope this helped.

SedJ601
  • 12,173
  • 3
  • 41
  • 59
14

If you are still getting an error that says "Default Activity not found" when you try to edit the run configurations even after executing:

Invalidate cache and Restart.

Then try deleting the Settings/Preferences folder:

/< USER_HOME_DIR >/.AndroidStudioPreview3.2

or on Mac :

/Users/<USER_NAME>/Library/Preferences/.AndroidStudioPreview3.2
Phileo99
  • 5,581
  • 2
  • 46
  • 54
  • If you have renamed your packages or you switched branches from your version control, sometimes Android Studio doesn't recognize all files and mess up things. The only solution that worked for me is to close AS, then deleted .AndroidStudioXY (where XY is your version number) which @Phileo99 pointed out. – Zbarcea Christian Oct 25 '18 at 10:09
  • 1
    You saved my life! Just do this /< USER_HOME_DIR >/.AndroidStudioPreview3.2 – nadafafif Nov 08 '18 at 10:11
  • you're welcome @nadafafif ! please upvote my answer if it helped you. – Phileo99 Nov 08 '18 at 18:14
  • @Phileo99 Already did that. Couldn't stop myself from doing it. :) Cheers. Keep helping like that. – nadafafif Nov 13 '18 at 10:41
  • That helped, but be aware that you will download a lot of stuff. It tooks around 15 minutes to download – Valgaal Feb 27 '19 at 23:48
10

When I clicked "Open Module Settings", there was no "Source" tab, I think because that's been removed for newer versions of Android Studio (I'm on 0.8.14). So I had to do this instead:

Add these lines to the build.gradle file inside the android { ... } block:

android { ... sourceSets { main.java.srcDirs += 'src/main/<YOUR DIRECTORY>' } }

After editing the file, click Tools > Android > Sync Project with Gradle Files.

Credit to this answer and this comment.

Community
  • 1
  • 1
Josh
  • 2,790
  • 26
  • 30
9

Following did the trick for me. From Run -> Edit Configuration.

enter image description here

CoDe
  • 11,056
  • 14
  • 90
  • 197
  • I would advice against this solution as it caused the application to no longer be shown in the list of available applications on the Samsung Galaxy S5 Neo and the Samsung Galaxy S6. – Teun Kooijman May 22 '16 at 10:44
3

My problem came down to an additional error that was popping up sometimes, stating

Manifest Merger failed with multiple errors in Android Studio

What ultimately was causing my problem was the fact that there were multiple manifests (a debug Manifest, and a manifest in the new module I had just imported), and they were not merging correctly due to this. After seeing this answer, I was able to analyze the merged manifest and find the cause of the issue and fix it.

ConcernedHobbit
  • 764
  • 1
  • 8
  • 17
3

enter image description here

Press app --> Edit Configurations
After that change value in Launch on "Nothing"

Valentin
  • 400
  • 2
  • 11
2

this happened to me because I capitalized the paths in the manifest. changed:

<intent-filter>
    <action android:name="ANDROID.INTENT.ACTION.MAIN"/>
    <category android:name="ANDROID.INTENT.CATEGORY.LAUNCHER"/>
</intent-filter>

to

<intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>

and it was fixed

dabluck
  • 1,641
  • 2
  • 13
  • 20
2

I ran into the same issue today and was going through the answers here.

For me the difference was that yesterday it worked fine, so I figured it could not really be a configuration issue, neither configuration nor Version of Android Studio changed.

Fortunately, I tried a restart of Android Studio before trying any of the other answers, and luckily that solved the issue.

So for all people out there who run into this: first thing to try is to restart Android Studio and only if that does not solve the issue try the other answers here.

Alexander Köb
  • 944
  • 1
  • 9
  • 19
2

I just experienced the same error in Android Studio 1.5.1. and just found the source of the problem. I am not sure whether the cause was a human error or some strange glitch in the behaviour of the IDE, but none of the existing StackOverflow questions about this subject seemed to show anything about this so I figured I post it as an answer anyway.

For me, either one of my team members or the IDE itself, had changed the launcher activities manifest entry, causing it to look like this:

        <activity
            android:name="com.rhaebus.ui.activities.ActivitySplash"
            android:launchMode="singleInstance"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <id android:name="android.intent.id.LAUNCHER" />
            </intent-filter>
        </activity>

While it should, in fact, look like this:

        <activity android:name="com.rhaebus.ui.activities.ActivitySplash"
            android:launchMode="singleInstance"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" /> <!-- Change Here -->
            </intent-filter>
        </activity>

So please double, triple, quadruple check the format of your launcher activity in the manifest and you might be able to save yourself some time.

Hope this helps.

EDIT: I strongly suggest people not to go with the answers that suggest to manually select a launcher activity inside the configuration options of your module, as this caused the application to no longer be shown in the list of installed apps on both the Samsung Galaxy S5 Neo and the Samsung Galaxy S6 (at least for me).

Teun Kooijman
  • 1,132
  • 2
  • 10
  • 23
2

You can get Android Studio not to complain by going to the "Edit Configurations" menu (tap "Shift" three times, type "Edit Configurations"), then change Launch Options > Launch to "Nothing".

I'll probably add a generic activity containing instructions, just to avoid any confusion.

Sayali
  • 132
  • 1
  • 5
1
  1. In Android Studio switch to Project perspective (not Android perspective).

  2. Make sure that your project follows the gradle plugin's default structure (i.e. project_dir/app/src/main/java...)

  3. Delete all build folders and subfolders that you see.

  4. In the toolbar click Build -> Clean Project, then Build -> Rebuild Project.

  5. Try to run the project.

gustavohenke
  • 40,997
  • 14
  • 121
  • 129
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
1

Please make sure in manifest that package name is same with your main activity

U three
  • 43
  • 7
1

In my case, it worked when I removed the .idea folder from the project (Project/.ida) and re-opened Android Studio again.

Yousef Gamal
  • 1,026
  • 2
  • 17
  • 32
  • Removing the .idea folder helped in my case, Thanks! For clarification all files with extension ".iml" were inside the .idea folder. Please DON'T remove only .iml files because this can lead to other errors! – Cordis Audax Agrinova Jul 30 '20 at 11:10
0
  1. Right click on the project and choose Open Module Settings.
  2. Go to the Sources tab in your module.
  3. Find your src folder.
  4. Right click on it and mark it as Sources.

This solved the error in my case.

ConquerAndroid
  • 231
  • 2
  • 3
0

If you changed name of directories (class structure) for example com.dir.sample to com.dir.sample1, after that don't forget to change package com.dir.sample to com.dir.sample1.

Zafer
  • 316
  • 4
  • 13
0

Modify "Workspace.xml" (press Ctrl + Shft + R to search it)

  1. Modify the activity name with package name

  2. Make sure to change "name="USE_COMMAND_LINE" to value="false"

  3. Reload the project

Done!

neo-av-in
  • 141
  • 1
  • 4
0

For those like me who were struggling to find the "Sources tab":

enter image description here

Here you have to mark your "src" folder in blue (first click in Mark as: Source, then in your src folder), and you're good to go.

Rocío García Luque
  • 3,597
  • 31
  • 31
0

There are two steps you can take:

  1. Go to configurations and enter the name of activity to be launched
  2. If it is still not working Disable Instant Run
Harish Rana
  • 484
  • 3
  • 8
0

I have tried all solutions, but not working at all. than I have tried to disable Instant run in my android studio.

Go to Android Studio Settings or Preferences (for MAC) -> Build,Execution,Deployment -> Instant Run.

uncheck the Instant run functionality and than after click sync project with gradle files from file menu

now run your build...

Mayur Sakhiya
  • 326
  • 2
  • 14
0

In some case you can have model with some category field, if you will refactor it in all places, it may refactor it in manifest file and then and the tag xml will became invalid.

Pavel Poley
  • 5,307
  • 4
  • 35
  • 66
0

Many possibilities can be happened for this kind of case (Default Activity not Found) If all code are fine, especially on Manifest, just just need to Invalidate Cache and restart the studio,

But sometime it is happened when you have duplicate activity declaration on manifest, not only for the Main activity, it is also triggered by child activities as well.

That happened with me, Default activity not found because i have duplication child activities on manifest, after deleted that, everything is well

masbayu
  • 71
  • 1
  • 4
0

Check if there is any duplicate tag in your AndroidManifest.xml file.

Devansh Maurya
  • 832
  • 12
  • 11
0

I figured it out. I mistakenly added final keyword in activity declaration. Once I removed it everything works!

public  class SplashActivity extends AppCompatActivity {
...
}
Asad35Waheed
  • 121
  • 11
0

In my case, this happened because of sudden shutdown of the system. I followed these steps:

  1. Close Android Studio
  2. Go to

C:\Users\my_user_name.AndroidStudio4.0\system\caches

  1. Delete "caches" folder
  2. Relaunch Android Studio
Vikrant_Dev
  • 430
  • 2
  • 15
-1
  1. In Android Studio

  2. Go to edit Configuration .

  3. Select the app.

  4. choose the lunch Activity path.

  5. apply, OK.

    Thanks!!

Community
  • 1
  • 1
Mstack
  • 321
  • 1
  • 12
-1

Default Activity name changed (like SplashActivity -> SplashActivity1) and work for me