Android java.lang.ClassNotFoundException error - Class is there, though - android

I'm creating an Android app that does a number of things and I've run into this issue that has stumped me for a couple of days. My Google-Fu isn't cutting it and I'm having to resort to asking for help on this one.
I've created a taken a working class from the CyanogenMod Project and begun to implement and modify it. Now, before I started to modify anything, I wanted to make sure it would run properly (as you should). That's when I his this error:
03-01 13:45:13.340: E/AndroidRuntime(8394): FATAL EXCEPTION: main
03-01 13:45:13.340: E/AndroidRuntime(8394): Process: com.ultima.settings, PID: 8394
03-01 13:45:13.340: E/AndroidRuntime(8394): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ultima.settings/com.ultima.settings.SettingsActivity}: android.view.InflateException: Binary XML file line #142: Error inflating class com.settings.ultima.NumberPickerPreference
and later in the log, which I think is of interest:
03-01 13:45:13.340: E/AndroidRuntime(8394): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.settings.ultima.NumberPickerPreference" on path: DexPathList[[zip file "/system/app/UltimaControl.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
03-01 13:45:13.340: E/AndroidRuntime(8394): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
03-01 13:45:13.340: E/AndroidRuntime(8394): at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
03-01 13:45:13.340: E/AndroidRuntime(8394): at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
03-01 13:45:13.340: E/AndroidRuntime(8394): at android.preference.GenericInflater.createItem(GenericInflater.java:375)
03-01 13:45:13.340: E/AndroidRuntime(8394): at android.preference.GenericInflater.createItemFromTag(GenericInflater.java:430)
03-01 13:45:13.340: E/AndroidRuntime(8394): ... 25 more
Now, the class is there. It's not dependant on any libraries or anything (that I know of, it uses NumberPicker, which is in the Android v19 source and is included anyway).
I've tried baksmali-ing the apk after compiling it, and sure enough the class is there (smali file).
There are no build errors, and if I remove this:
<com.settings.ultima.NumberPickerPreference
android:key="pref_key_workspaceRows"
android:title="#string/launcher_title_workspace_rows"
ultima:min="1"
ultima:max="10" />
from the preferences.xml it no longer force closes, or gives any kind of error.
I'm at a loss as to what could be the issue :(
EDIT:
Here's the CyanogenMod project I've forked and I'm editing.
I'm editing the NumberPreference and the preferences.xml and adding them to my own app (to make room for other things in the settings instead - hard to explain).
Obviously these are the originals, not the ones in my app, but I've made the necessary alterations to the,. Changed the package names, etc.

Related

google maps api app keeps stopping in android studio

I am trying to create an application which utilizes Google Maps API. I followed the instructions (installed Google Play Services, created an API key, copied, and then pasted it in .xml file), but when I try to run this app, I get "Maps Demo (the name of the app) keeps stopping" message. (I use Nexus 5 API 28 AVD as an emulator) What might be reasons for that and how to solve this problem?
Logcat:
--------- beginning of crash
2018-11-24 09:07:55.191 2653-2803/? E/AndroidRuntime: FATAL EXCEPTION: Thread-6
Process: com.example.user.mapdirectionsample, PID: 2653
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/http/ProtocolVersion;
at fa.b(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):3)
at ez.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):3)
at fb.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):15)
at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):6)
at ee.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):21)
at ee.run(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):8)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.apache.http.ProtocolVersion" on path: DexPathList[[zip file "/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk"],nativeLibraryDirectories=[/data/user_de/0/com.google.android.gms/app_chimera/m/0000000d/MapsDynamite.apk!/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at ac.loadClass(:com.google.android.gms.dynamite_dynamiteloader#14574084#14.5.74 (100700-219897028):4)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at fa.b(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):3) 
at ez.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):3) 
at fb.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):15) 
at com.google.maps.api.android.lib6.drd.al.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):6) 
at ee.a(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):21) 
at ee.run(:com.google.android.gms.dynamite_mapsdynamite#14574084#14.5.74 (100700-219897028):8) 
Thanks in advance.

Unable to instantiate activity ComponentInfo in android

I make a project and test it.
I test in my device Galaxy S7(Mashmellow), it works fine, but another device SHV-205(Kitkat), it occurs error like this.
09-23 15:24:45.981 10438-10438/com.thewell.thewell_dev.companylink E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thewell.thewell_dev.companylink, PID: 10438
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thewell.thewell_dev.companylink/com.thewell.thewell_dev.fourslink.Activity.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "com.thewell.thewell_dev.fourslink.Activity.SplashActivity" on path: DexPathList[[zip file "/data/app/com.thewell.thewell_dev.companylink-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.thewell.thewell_dev.companylink-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
I use android studio.
I test it and upload to Google play store, but it works fine.
I don't know why this problem occurs this error.
please help me
I faced this Error already, and found the solution myself,
If you are placed you splashscreen activity in your Activity package, please move it to outer package(Main package)
as shown in below Image..!

Duplicated Play Store app fails to instantiate

Compiled an APK and tested it successfully on my device, tried it through the Google Play Store and it stops working immediately. This app is a copy of an existing app, since you cannot have the same package name twice I simply renamed the package name in the AndroidManifest.xml, compiled it, tested it and then uploaded it to the Play Store.
I do not understand why the app works when I copy it to a device but the same app fails when loaded through the Play Store. I generated a crash report which I accessed from the Play Store Developer Console. If anyone has experience of successfully duplicating apps on the Store then your help would be appreciated.
java.lang.RuntimeException: Unable to instantiate application de.schildbach.wallet.artbyte.WalletApplication: java.lang.ClassNotFoundException: Didn't find class "de.schildbach.wallet.artbyte.WalletApplication" on path: DexPathList[[zip file "/data/app/de.schildbach.wallet.artbyte-1/base.apk"],nativeLibraryDirectories=[/data/app/de.schildbach.wallet.artbyte-1/lib/arm, /data/app/de.schildbach.wallet.artbyte-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:680)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1800(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.ClassNotFoundException: Didn't find class "de.schildbach.wallet.artbyte.WalletApplication" on path: DexPathList[[zip file "/data/app/de.schildbach.wallet.artbyte-1/base.apk"],nativeLibraryDirectories=[/data/app/de.schildbach.wallet.artbyte-1/lib/arm, /data/app/de.schildbach.wallet.artbyte-1/base.apk!/lib/armeabi, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at android.app.Instrumentation.newApplication(Instrumentation.java:1005)
at android.app.LoadedApk.makeApplication(LoadedApk.java:670)
... 9 more
Suppressed: java.lang.ClassNotFoundException: de.schildbach.wallet.artbyte.WalletApplication
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
The Exception says that build is failed due to class not found on dex path list. Build the apk by cleaning the project and also recompile the native code using the ndk-build command. Then try it on the local device and then upload to play store.
The package name in AndroidManifest.xml is often also used for the code base, e.g. as class name of the activities. If you only rename the package name but leave the Java/dex code unchanged Android will not be able to find some classes as you already have noticed.
Check the AndroidManifest.xml for package relative class names (those that start with a .) and prepend the old package name:
Example
Old package name: org.example.myapp
Old activity name: <activity android:name=".MyActivity" ..>
New package name: com.example.newappname
New activity name: <activity android:name="org.example.myapp.MyActivity" ..>

Rare Android Unable to Instantiate Application Exception

I'm seeing the following exception under Crashes in the dev console from time to time.
Whats puzzling about it is that google maps shows up in the call stack as if its calling or creating my app class - very confusing. Whats further weird is the "MyApp-2.apk" in the call stack - where it appends the "-2".
I do include the android.maps.jar file in the libs.
I would like to know how to recreate this if possible and how to prevent this from happening?
java.lang.RuntimeException: Unable to instantiate application com.MyApp.MyCustomApp:
java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp"
on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
at android.app.LoadedApk.makeApplication(LoadedApk.java:503)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4405)
at android.app.ActivityThread.access$1400(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1327)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5059)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.MyApp.MyCustomApp" on path: /system/framework/com.google.android.maps.jar:/data/app/com.MyApp-2.apk
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.newApplication(Instrumentation.java:967)
at android.app.LoadedApk.makeApplication(LoadedApk.java:498)
... 11 more
Manifest Application Tag:
<application
android:name=".MyApp"
android:hardwareAccelerated="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppBaseTheme" >
I'm using these JARS: android-support-v4-r2-googlemaps.jar + android-support-v4.jar
The prime reason why a Class within your application would be present on your test devices but missing at runtime on some others would be if your class has a dependency on some external feature which is missing on those devices. For example, if you used some Google API which is not part of AOSP and so missing on a plain AOSP build, or a vendor build which does not license these, then your class will be pruned at install time as its dependencies cannot be resolved.
A common reason for your app finding its way into such circumstances might be someone running an inconsistently assembled "custom ROM" on their device.

What could be causing a ClassNotFoundException?

So I've been working on an app lately which runs fine on most devices. However, sometimes the app crashes at start up with the following error:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.mypackage.app/com.mypackage.app.activities.MainPager}:
java.lang.ClassNotFoundException: com.mypackage.app.activities.MainPager
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
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:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:115)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException:
com.mypackage.app.activities.MainPager
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:1053)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1986)
... 12 more
I get that this is because it can't find the class called MainPager. But how is that even possible? I mean, the class should be there.. I put it there myself :) . Why on earth is it not finding it?
EDIT: I think the cause may be that in my manifest I have android:package="com.mypackage.app" defined, but that my launch activity is in the package com.mypackage.app.activities. Currently testing this theory. Still weird that it only happens on some devices, though.
This solution won't work, since I then can't update the APK in Google Play (has to be the same package name in the manifest).
Since ADT update to revision 22 (May 2013) you have to check "Android Private Libraries" check box in Project -> Properties -> Java Build Path -> Order and Export in Eclipse for your older projects to get rid of this exception ...
in the manifest you add Activity name like this
android:name=".activities.MainPager"
because you have given package name
android:package="com.mypackage.app"
Now I am using ART runtime on Nexus 5, and I am getting ClassNotFound for some apps.
You can safely ignore those if that's the case for your users.

Categories

Resources