user6000127
user6000127

Reputation:

Android app closes immediately after launching

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.

Upvotes: 1

Views: 28858

Answers (4)

user22553717
user22553717

Reputation: 1

maybe you have double setContentView in your onCreate in mainactivity.java

and maybe missing classes error found in your activity_main.xml

go to activity_main. xml click on error missing classes click on create class

**final solution **

open your logcat panel for your device to see where the error comes from

for me it was MainThread. it took my day to figured out.

Upvotes: 0

Loodle
Loodle

Reputation: 11

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.

Upvotes: 0

Muhammad Rizwan
Muhammad Rizwan

Reputation: 37

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

Upvotes: 0

wblaschko
wblaschko

Reputation: 3262

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).

Upvotes: 2

Related Questions