Android Flow example crashes with ClassNotFoundException - android

I'm Naive in Android development. I tried to use flow/mortar for development and stuck with an exception.
Here's what I did. In Eclipse, I chose New (Crtl N) -> Android Project from existing code and imported the flow sample downloaded from the square flow website https://github.com/square/flow/.
Eclipse marked errors in all the files as the package name was not matching the file's location. So to fix the package mismatch issue, I moved the files from : \flow-master\flow-sample\src\main\java\com\example\flow to : \flow-master\flow-sample\src\com\example\flow.
After this, I got some more errors saying 'Unresolved to a Type' which I fixed by importing proper jar files. Now all the errors are cleared and I tried to install and launch the app.
The app crashes as soon as we launch with the Logcat error below:
E/AndroidRuntime(5438): FATAL EXCEPTION: main
E/AndroidRuntime(5438): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.flow/com.example.flow.MainActivity}: java.lang.ClassNotFoundException: com.example.flow.MainActivity
E/AndroidRuntime(5438): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1888)
E/AndroidRuntime(5438): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1989)
E/AndroidRuntime(5438): at android.app.ActivityThread.access$600(ActivityThread.java:126)
E/AndroidRuntime(5438): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1155)
E/AndroidRuntime(5438): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(5438): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(5438): at android.app.ActivityThread.main(ActivityThread.java:4482)
E/AndroidRuntime(5438): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(5438): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(5438): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
E/AndroidRuntime(5438): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
E/AndroidRuntime(5438): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(5438): Caused by: java.lang.ClassNotFoundException: com.example.flow.MainActivity
E/AndroidRuntime(5438): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(5438): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(5438): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(5438): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime(5438): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1879)
E/AndroidRuntime(5438): ... 11 more
The error says that the file MainActivity is not found even when the file is available in the path com.example.flow.. Can someone please help me understand what the issue is?
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.flow"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18"/>
<application
android:icon="#drawable/flow_icon">
<activity
android:label="Flow"
android:name="com.example.flow.MainActivity"
android:theme="#android:style/Theme.Holo.Light.DarkActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>

Related

How to avoid class not found exception in android

I am getting class not found exception on some android devices, it's happening only on some devices.
This is the call-stack i have got,
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.picframes.android/com.picframes.android.first}: java.lang.ClassNotFoundException: com.picframes.android.first
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2240)
at android.app.ActivityThread.access$600(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:4987)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.picframes.android.first
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2112)
Any suggestions for resolving this problem, I could not reproduce this problem on my device.
On devices with which android version program works and where it doesn't work? I am not sure if this is the case but you probably get this error on older devices, is that right? You should make sure that all the functionality of your program is available on older systems. Use your manifest file:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
to define minimum sdk version, and you will get errors in your code if you are trying to use features that are not available on the device that you target.

When people download my app from the google play i get this error: java.lang.RuntimeException: Unable to instantiate activity

my name is Walid.
im having this error when people download my app from google play i get this error
i think its when certain devices download the app it causes the app to crash .
this is the sdk in the manifest.
please if anyone knows how to fix this please let me know .
Thank you.
<uses-sdk
android:minSdkVersion="2"
android:targetSdkVersion="17" />
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{tigris.code.oneallah.walid/tigris.code.oneallah.walid.MenuPage}: java.lang.ClassNotFoundException: tigris.code.oneallah.walid.MenuPage in loader dalvik.system.PathClassLoader[/data/app/tigris.code.oneallah.walid-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: tigris.code.oneallah.walid.MenuPage in loader dalvik.system.PathClassLoader[/data/app/tigris.code.oneallah.walid-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1565)
... 11 more
Your APK file does not contain a class named tigris.code.oneallah.walid.MenuPage. Either the APK is missing the class, or ProGuard renamed it.

Android - exception launching project on start after copying a lot of code over from another project

am getting this exception:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{business.premium/business.premium.Problemio}:
java.lang.ClassNotFoundException: business.premium.Problemio
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
... 11 more
java.lang.ClassNotFoundException: business.premium.Problemio
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
it says that class is not there, but it IS there. I tried to configure things in my project's build path, but not too sure what to tweak there.
And here is how I start my Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="business.premium"
android:versionCode="1"
android:versionName="1.0" >
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="15"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:name="MyApplication"
android:debuggable="true">
<activity
android:name=".Problemio"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any thoughts on how to solve this, or what to look into? Thanks!
Its because you specified the "android:name" attribute in the application node in the manifest file.
Do not use the android:name attribute!
It, misleadingly, does not have anything to do with the name of your app and is actually the name of an extra class to load before loading your application. That's why you are getting the ClassNotFoundException.
Remove it and it should work:
<application
android:icon="#drawable/icon"
android:label="#string/app_name"
android:description="#string/help_text" >
This answer is taken from: java.lang.ClassNotFoundException on working app

Android ClassNotFoundException on published app

I have an application thats been published awhile on Google play, I have been fixing reported bugs as they come in but recently this log below came in and I don't know what to make of it:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.mammothtooth.flightinfo/com.mammothtooth.flightinfo.ui.SplashActivity}: java.lang.ClassNotFoundException: com.mammothtooth.flightinfo.ui.SplashActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/com.mammothtooth.flightinfo-1/pkg.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1743)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4277)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.mammothtooth.flightinfo.ui.SplashActivity in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/mnt/asec/com.mammothtooth.flightinfo-1/pkg.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at android.app.Instrumentation.newActivity(Instrumentation.java:1040)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1735)
Does anyone know anything about this type of error log? My SplashScreenActivity is there and its defined as the entry point of the application in the manifest as follows:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
<uses-library android:name="com.google.android.maps" />
<activity
android:label="#string/app_name"
android:name=".ui.SplashActivity"
android:theme="#android:style/Theme.NoTitleBar"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="portrait">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Would the placing of the uses-library be an issue in the manifest?
I can't reproduce this issue on any of my android devices so any help is greatly appreciated in locating what might be the cause of this issue.

ClassNotFoundException on Galaxy Tab (only)

I have a working Android application. It works on more than 500 different devices. The manifest is
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.decamps.droid.photoid" android:versionCode="5"
android:versionName="1.4">
<application android:icon="#drawable/icon" android:label="#string/app_label"
android:name="PhotoIDroid" android:description="#string/app_desc"
android:debuggable="FALSE">
But when it it launched from a Samsung Galaxy Tab, it doesn't start and crashes with:
java.lang.RuntimeException: Unable to
instantiate application
info.decamps.droid.photoid.PhotoIDroid:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:670)
at
android.app.ActivityThread.handleBindApplication(ActivityThread.java:4483)
at
android.app.ActivityThread.access$3000(ActivityThread.java:135)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2181)
at
android.os.Handler.dispatchMessage(Handler.java:99)
at
android.os.Looper.loop(Looper.java:144)
at
android.app.ActivityThread.main(ActivityThread.java:4937)
at
java.lang.reflect.Method.invokeNative(Native
Method) at
java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at
dalvik.system.NativeStart.main(Native
Method) Caused by:
java.lang.ClassNotFoundException:
info.decamps.droid.photoid.PhotoIDroid
in loader
dalvik.system.PathClassLoader[/data/app/info.decamps.droid.photoid-1.apk]
at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at
android.app.Instrumentation.newApplication(Instrumentation.java:945)
at
android.app.ActivityThread$PackageInfo.makeApplication(ActivityThread.java:660)
... 11 more
How an the Samsung Galaxy not find the application class?
Any clue on how to resolve this?
I have been able to reproduce tis crash on the Samsung Galaxy emulator.
I have removed the android:name attribute declaration from the AndroidManifest.xml and it now works.

Categories

Resources