26

I have a splash activity which starts another activity like this

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        final Thread splashThread = new Thread() {
            @Override
            public void run() {
                try {
                    int wait = 0;
                    while (_isActive && (_splashTime > wait)) { 
                        sleep(100);

                        if (_isActive) {
                            wait += 100;
                        }
                    }
                } catch (InterruptedException e) {
                    Log.d(TAG, e.getMessage());

                } finally {
                    startActivity(new Intent("com.path1.path2.SomeActivity"));
                    finish();
                }
            }
        };
        splashThread.start();
    }

To start another activity I use string parameter for the Intent constructor. The corresponding class is paired with the splash string like this

   <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.path1.path2"
          android:versionCode="2"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4"/>

    <!--permissions-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>

    <application android:label="@string/app_name" android:icon="@drawable/icon">
        <activity android:name=".SplashActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".SomeActivity"
                  android:label="@string/app_name"
                >
            <intent-filter>
                <action android:name="com.path1.path2.SomeActivity"/>
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".OtherActivity" android:label="@string/app_name"
                />

        <!--services-->
        <service android:name=".AlarmService"/>

    </application>
</manifest>

This works flawlessly UNTIL I rename the package name. I rename the package name in the Manifest by using refactoring and the IDE renames all other classes accordingly. But when I want to start newly renamed project, I face an error

Launching application: com.path1.pathOLD/com.path1.path2.SplashActivity.
DEVICE SHELL COMMAND: am start -n "com.path1.pathOLD/com.path1.path2.SplashActivity"
Starting: Intent { cmp=com.path1.pathOLD/com.path1.path2.SplashActivity }
Error type 3
Error: Activity class {com.path1.pathOLD/com.path1.path2.SplashActivity} does not exist.

It seems that the app tries to start the Splash activity using OLDpath/NEWpath.Splash path and the error is there, but I can't find why it is using such path.

I use IntelliJ IDE. Any ideas? Could it be in the Filter in the 2nd activity in the Manifest?!

sandalone
  • 41,141
  • 63
  • 222
  • 338

11 Answers11

42

It is a bug in Android Studio. To fix it:

  1. Close Studio.
  2. Remove .idea/workspace.xml
  3. Launch Studio.
sasha_trn
  • 1,935
  • 2
  • 23
  • 30
31

The error was in IntelliJ IDEA after all. When you create a project, the Configuration checks Launch feature automatically and prints the name of default class. When you change the name of package, refactoring does not change the configuration string which still points to the old class name. That is why there was not compile-time error, but runtime error.

It would be great if they could fix this issue in this awesome IDE as these kind of errors are very hard to track down (this one took 4 months to realize where the error was).

sandalone
  • 41,141
  • 63
  • 222
  • 338
  • 1
    I think, Eclipse has inbuilt updating task for package name at the time of launching application. – user370305 Nov 21 '11 at 08:36
  • 1
    This is a horrible bug in a great IDE. I went from Eclipse to IntelliJ and have not had any problems until this bug hit me. Thank you for answering your own question for the rest of us. You are a good community member. – Phobos Feb 24 '13 at 03:36
  • Thanks so much for answering your own question. I added new activity which I wanted to start first, but IntelliJ IDEA kept saying that I must add to an old one. Solution was to set radio button to Launch Default Activity – Alexander Romanov May 05 '13 at 08:44
  • 1
    Great job finding the solution. I found the screen you show here at the top menu at run>edit configurations, and after changing to "launch default activity" the project ran. –  May 26 '13 at 08:46
  • Thank you. The option "start default activity" was active and seemed to find the wrong activity internally, so now I´ve choosen the start activity manually – Marian Klühspies Apr 14 '14 at 08:53
  • Nothing helped until I tried delete cache as described here http://stackoverflow.com/a/25602161/630833 – jayeffkay May 27 '15 at 11:37
  • This is **still** existing in 2016.3.4! I think this would have taken ages for me and I would have just renamed it back... This should really(!) be fixxed... – geisterfurz007 Feb 22 '17 at 08:01
7

File -> Invalidate caches/Restart may fix this type of errors

Ali
  • 2,702
  • 3
  • 32
  • 54
Arjun
  • 358
  • 2
  • 13
4

Did you notice this difference (For package name in manifest),

The Launching Activity is com.path1.pathOLD/com.path1.path2.SplashActivity.

Change package in manifest file .. use this modified manifest and let me know what happen..

EDIT: Modified Manifest file,

<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.path1.path2"
      android:versionCode="2"
      android:versionName="1.0">
<uses-sdk android:minSdkVersion="4"/>

<!--permissions-->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name=".SplashActivity"
              android:label="@string/app_name"
            >
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity android:name=".SomeActivity"
              android:label="@string/app_name"
            >
        <intent-filter>
           <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    <activity android:name=".OtherActivity" android:label="@string/app_name"
            />

    <!--services-->
    <service android:name=".AlarmService"/>

</application>

user370305
  • 108,599
  • 23
  • 164
  • 151
  • Ah!!! we both have the answer but I took it a while to describe the whole answer, never mind +1. I think this is the only problem. – Lalit Poptani Nov 18 '11 at 09:29
  • 1
    @Lalit Poptani - I think, In manifest file have problem, look at this line too, this in . – user370305 Nov 18 '11 at 09:31
  • @user370305 I also think that the problem is in the filter. But why it does not work if I renamed both string paths accordingly. It works usually, but it does not work ONLY after renaming the package name. – sandalone Nov 18 '11 at 09:35
  • @user370305 As I told Lalit, the error is not in the Manifest in the activity name, it was my typo. Sorry! – sandalone Nov 18 '11 at 09:36
  • Please correct your answer so that we do not confuse others. Thanks – sandalone Nov 18 '11 at 09:37
  • I think now the problem should be resolved it was the package name error. – Lalit Poptani Nov 18 '11 at 09:44
  • It is not, please look at the rewritten question. I confused names while writing the question, while the manifest holds the write names. – sandalone Nov 18 '11 at 09:46
3

In my case I followed all the answers from here, but also I had to clean the cache. I followed this steps:

1. Go to ~/.gradle/ and delete caches folder
   rm -r caches
2. "Sync project with Gradle files" icon on Android Studio
3.  Run project
Jorge Casariego
  • 21,948
  • 6
  • 90
  • 97
0

I've had the same error message in Eclipse/ADT (usually when two people are working on the same project using different IDEs) and fixed it by adding the package name to the beginning of the Activity name (and all the other Activities, Receivers, Services, etc.) in AndroidManifest.xml.

In this example, that would mean changing this:

<activity android:name=".SplashActivity"

To this:

<activity android:name="com.path1.path2.SplashActivity"
Josh
  • 2,790
  • 26
  • 30
0

I had this problem and it was because of a problem in manifest file. Make sure your manifest file doesn't have any problem.

Hesam
  • 52,260
  • 74
  • 224
  • 365
0

Had the same problem. After trying everything in this thread it turned out to be Android Studio's instant run.

Disabling this fixed the issue straight away as does deleting everything under .android/build-cache (of the specific build if you can find it). The reason being is that instant run appears to use a cached version of the app which isn't even removed during a regular clean/rebuild.

tom808
  • 320
  • 2
  • 11
0

I also had this problem and specifically when switching flavours. So what solved it for me is disabling Instant Run in android. I will like to include some important points regarding this-

  • Make sure your manifest is ok.
  • Maximum times cleaning the project and rebuilding it will solve the problem.
  • Disable instant run in the android studio above 2.1.
  • Uninstall the app and reinstall it.
Arpan Sharma
  • 2,142
  • 11
  • 22
0

Make sure your package name is same in Gradle , Manifest. Go to Module Settings -> Flavors -> Application ID -> (your package Name)

Cloy
  • 2,141
  • 23
  • 32
0

I also got below error after renaming my package:

The launcher activity com.path1.abc/com.path2.abc.SplashActivity does not exist.

I made sure that the package name is updated and also includes these files

  • google_services.json
  • AndrodiManifest.xml
  • build.gradle

Finally uninstalled the previous app, clean, and run the project. That worked for me.

Ishaan
  • 3,658
  • 2
  • 23
  • 39
vids
  • 381
  • 3
  • 5