Reputation: 3152
I refactored my package name and put my CuteMainActivity
in the package org.azurespot.cutemain.CuteMainActivity
. Plus rearranged all my other classes. So now I get a red error on the .CuteMainActivity
part in my Manifest, where the activity should launch.
I also changed the top package name of my Manifest to the new one: org.azurespot
, and also changed my applicationID in my build.gradle
file to the new package name org.azurespot
too. Then I rebuilt, cleaned, and even tried invalidate and restart
to my project but nothing is getting rid of this red error. I also tried to assign the new package/activity name to launch in my run configurations, and got this error:
Launching application: org.azurespot/org.azurespot.cutemain.CuteMainActivity.
DEVICE SHELL COMMAND: am start -n "org.azurespot/org.azurespot.cutemain.CuteMainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.azurespot/.cutemain.CuteMainActivity }
Error type 3
Error: Activity class {org.azurespot/org.azurespot.cutemain.CuteMainActivity} does not exist
One strange thing, is that my package name has the word (androidTest)
beside it. Would that make things not work? Usually studio creates a regular package name and a package_name (androidTest)
, but in the refactoring, I only see this (androidTest)
one.
I have been researching this problem for a while, but nothing seems to work. Any suggestions? Thank you.
Manifest.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.azurespot" >
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".CuteMainActivity" //This has a red error
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
LogCat after changed Manifest
name to ".cutemain.CuteMainActivity"
1480-1480/org.azurespot E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: org.azurespot, PID: 1480
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.azurespot/org.azurespot.cutemain.CuteMainActivity}: java.lang.ClassNotFoundException: Didn't find class "org.azurespot.cutemain.CuteMainActivity" on path: DexPathList[[zip file "/data/app/org.azurespot-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.azurespot-2, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.azurespot.cutemain.CuteMainActivity" on path: DexPathList[[zip file "/data/app/org.azurespot-2.apk"],nativeLibraryDirectories=[/data/app-lib/org.azurespot-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 3464
Reputation: 3152
Ah... the package name with (androidTest)
was indeed the culprit. All of the above answers should have fixed things, but the final problem was that when I refactored (I have no idea how it happened), all of my new package names got put into my androidTest
directory in the src
folder, and nothing was in my main
of my src
folder. So when my app went looking for the main activity, it could not be found. The fix to this was to put the whole java
folder back into the main
folder (as it was empty for some reason), then restart the app and everything worked again. It was not necessary to delete the androidTest
folder, and it seems fine that it's empty.
Upvotes: 1
Reputation: 10777
You should change it to one of the followings:
android:name="org.azurespot.cutemain.CuteMainActivity"
or
android:name=".cutemain.CuteMainActivity"
Upvotes: 1