1

I'm trying to finish off my app for publishing on the google play store so uploaded to the alpha testing phase. When trying to launch the app it closes immediately and this is the error that I receive:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.FinalFrontier.MoonLanding/com.FinalFrontier.MoonLanding.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2192)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2316)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1298)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:5225)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.FinalFrontier.MoonLanding.MainActivity" on path: DexPathList[[zip file "/data/app/com.FinalFrontier.MoonLanding-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.FinalFrontier.MoonLanding-1, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2183)
... 11 more

​ This is my first ever app and I'm pretty new to this so any help would be greatly appreciated. I've read the documentation and searched the errors online however can't seem to get any of the solutions to work. Here's a copy of my android manifest.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="2" android:versionName="1.1" package="com.FinalFrontier.MoonLanding" android:installLocation="preferExternal">
<application android:icon="@drawable/app_icon" android:label="@String/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:label="@String/app_name" android:name="com.FinalFrontier.MoonLanding.CustomActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
</activity>
<activity android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:hardwareAccelerated="true" android:name="com.unity3d.ads.android.view.UnityAdsFullscreenActivity" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" xmlns:tools="http://schemas.android.com/tools" tools:ignore="UnusedAttribute" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="23" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

Anybody got any ideas? Thanks in advance.

  • 5
    ***`Didn't find class "com.FinalFrontier.MoonLanding.MainActivity"`*** looks pretty explicit – Jim Garrison Mar 16 '16 at 17:36
  • 1
    It's been a long day but the manifest says the name of the main activity is com.FF.ML.CustomActivity. Should it be complaining about not finding it instead? – Roy Falk Mar 16 '16 at 17:49
  • Try to remove `android:installLocation="preferExternal"` from manifest file. – dzikovskyy Mar 17 '16 at 00:10

3 Answers3

2

Essentially what is happening is your application is unable to find the class it's looking for in the compiled APK and is crashing.

This can happen for several reasons.

Try this first

The most common I've found is that the IDE has messed up its build cache somewhere. In this case: restart Android Studio, clear the cache, and rebuild the project.

Try this second

It's also possible that you have enough methods that you're pushing the Android method limit (see this), in which case you'll have to enable multidex in your application or use Proguard to minimize your app (this is more complicated, but start here).

Community
  • 1
  • 1
wblaschko
  • 3,252
  • 1
  • 18
  • 24
0

I believe you are calling the finish(); method. Remove it, and then it will work fine.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
0

System searches for a class and can't find it in place where is searches: ClassNotFoundException Did you put the class file in the right directory, my fren?

I killed half an hour on the exact same problem and eventually it was just wrong folder I'm keeping my file in.

Loodle
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '23 at 07:41