Class extending Application throws ClassNotFoundException - android

I have a class that extends the application class and sometimes in my developer console I see an error saying ClassNotFoundException
java.lang.RuntimeException: Unable to instantiate application ecm2.android.ActiveStore: java.lang.ClassNotFoundException: ecm2.android.ActiveStore
at android.app.LoadedApk.makeApplication(LoadedApk.java:501)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4221)
at android.app.ActivityThread.access$1400(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4918)
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:1004)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: ecm2.android.ActiveStore
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:982)
at android.app.LoadedApk.makeApplication(LoadedApk.java:496)
... 11 more
This is how I declare it in my manifest
<application
android:name=".ActiveStore"
android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
ActiveStore is just a class that holds an application context to start and cancel alrams so why would I get this error?
Update:
I am still seeing this error from time to time in my developer page even after putting a . infront of the class name. It seems to only happen on an update or new install

Probably because you're missing the dot in front of the class name (which helps to tell Dalvik that your class belongs to the package of your app)
.ActiveStore
But if in doubt, post both the whole Manifest file and your .java

In your manifest you should either have something like:
package="path.to.project.root"
...
<application
android:name=".MyApplication"
or as has been mentioned already
<application
android:name="path.to.project.root.MyApplication"
Also make sure the constructor of your MyApplication class is public.

I'm also seeing this problem a lot and have no explanation.
I've seen people saying that it can happen AFTER a crash. Supposedly, after a crash, the ClassLoader could be in a "bad" state and not be able to load classes.
Basically this would mean that a prior bug is the real source of this problem.
Sorry to be vague, please update if you find a more precise explanation.

If you have code that needs to run on startup (e.g. a BroadcastReceiver on BOOT_COMPLETED or an AppWidget), you can get this if the user has installed your app on an external SD card. At this point the SD card may not have been mounted yet, thus your Application class can't be loaded. You can solve this by setting the installation mode to internalOnly or in the case of the BroadcastReceiver wait for the broadcast of ACTION_MEDIA_MOUNTED. See android intent for sdcard ready

I have experienced this before when I extended or implemented one of the classes/interfaces that was not available in a particular api level.
It doesn't tell this in a proper way.

I have seen this when there are verify errors for a different class the class in question depends on. Scroll back and see if there are any verification errors in the full logcat output.
If ecm2.android.ActiveStore depends on a class that fails verification, then you would get a class not found for ecm2.android.ActiveStore, not for the class ecm2.android.ActiveStore depends on.

Have you tried using the fully qualified package name to reference your class in your manifest?
.ActiveStore
would become
com.myapp.package.ActiveStore
By any chance are you using ProGuard or anything similar to obfuscate your code?

Related

Does anybody know whether a system app can extend VpnService in Android or not?

Now, I want to develop a system app which will extend VpnService. But when I call the method 'establish()' to initialize an instance of ParcelFileDescriptor. I got an exception in android 5.0 as below:
08-23 20:47:35.482 12344-12365/com.vm.shadowsocks W/System.err: java.lang.SecurityException: Cannot find com.vm.shadowsocks.core.LocalVpnService
at android.os.Parcel.readException(Parcel.java:1546)
at android.os.Parcel.readException(Parcel.java:1499)
08-23 20:47:35.483 12344-12365/com.vm.shadowsocks W/System.err: at android.net.IConnectivityManager$Stub$Proxy.establishVpn(IConnectivityManager.java:1779)
at android.net.VpnService$Builder.establish(VpnService.java:768)
at com.vm.shadowsocks.core.LocalVpnService.establishVPN(LocalVpnService.java:467)
at com.vm.shadowsocks.core.LocalVpnService.runVPN(LocalVpnService.java:256)
at com.vm.shadowsocks.core.LocalVpnService.run(LocalVpnService.java:239)
Thanks!
A normal (user) app can extend VpnService (documentation) so I don't know why a system app shouldn't be able to do this.
To interpret you error message is however rather hard frankly, without knowing any of your code. Also, you maybe might want to use an existing (open-source) implementation like e.g. strongSwan.

IllegalArgumentException in LoadedApk.forgetReceiverDispatcher()

I have an Android application in android market, I am getting the following error report,
I have used webView, zoom controls, these are all working fine, when ever I test it on OS 2.2,2.3,4.04,4.1,4.2. I don't know when this crash occur, either on zoom control or in loading .apk file from the market.
I am getting these error reports from several users, Please let me know what is this problem and how i can resolve this issue,
Thanks in advance.
java.lang.IllegalArgumentException: Receiver not registered: android.widget.ZoomButtonsController$1#43335900
at android.app.LoadedApk.forgetReceiverDispatcher(LoadedApk.java:628)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:1178)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:361)
at android.widget.ZoomButtonsController.setVisible(ZoomButtonsController.java:405)
at android.widget.ZoomButtonsController$2.handleMessage(ZoomButtonsController.java:179)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
I had the same problem, and successfully used this workaround:
ViewFlipper : Receiver not registered
You should basically create your own ViewFlipper subclass, and override it's onDetachedFromWindow function to stop flipping instead of crushing.
Than use that subclass in your layout.

Unable to instantiate application when it obviously exists

Since I've started developing an application I haven't received any "Unable to instantiate application" exceptions , however, after the launch there've been quite a number of bug-reports that stated this exception.
My application uses custom MyApplication class inherited from Application, manifest's record looks like .application.MyApplication and I still can't reproduce the same exception neither on 2.3 nor on 4.0. Can you suggest what might be happening there ?
UPD
Thanks.

android developer crash report

I have an application on google play.
I made a new version with a higher versioncode and different name.
Tested it on my own android device (v2.3.3) and an emulator (v4.0.3).
No errors so far, so i put the update on the market.
Now the first error reports come in!!!!! (see below)
I dont know what it means.
The new update was a little change in the permissions and i removed two libraries (jumptap SDK and jumptap adapter for admob mediation).
The removed permissions were:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Leaving these two for admob ads:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
The error code:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.masked.app/com.masked.app.mainjava}:java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2705)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2721)
at android.app.ActivityThread.access$2300(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2071)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4669)
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:876)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.masked.app.mainjava.onCreate(mainjava.java:53)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
At line 132 there is "adblockcheck();" that can be found here
How to prevent ad blocker from blocking ads on an app ;
line 123 is also within this code.
At line 53 a mediaplayer is started (mp.start();) with a starting sound.
What is the problem exactly, and why don't i get the error on my devices?
This is my first error report through google play, is one error problematic or are there more developers that experience errors and don't always care about them?
Full Mainjava.java can be downloaded here http://homepage.tudelft.nl/78u5u/main.zip
EDIT:
R.raw.start is a mp3 file.
Obviously, your MediaPlayer mp instance is null. It means that MediaPlayer.create method returned null.
As said in android documenation for create method:
Returns
a MediaPlayer object, or null if creation failed
I think, android can't create MediaPlayer for you beacuse of lack required codecs or so on. What is format of your R.raw.start file? You can try to play with formats.
Whatever, you need to gracefuly handle this exception.
Also, as just said before, I advice you to use ACRA. It can help you resolve problems quickly. By my expirence, Android users don't like to send error reports. Less than 10% of errors are reported to the google play.
UPDATE:
ACRA is good enough, but not perfect, because of blocking. It means that if app is just crashed and user have slow internet connection, you can get the ANR message. Let imagine: User thinks that app is just hang, and decided to wait for app response and then gets "Sorry, app crashed" message. You must find the way to send reports via background service or so on before using ACRA.
Also, Google Docs - default backend for sending errors - is awful. It is highly recommended to use another backend. If your app is small enough and you think you will receive less 500 error reports in a month you can try proprietary BugSense, it is supports ACRA.
It's going to be hard to tell what is really going on without seeing (at least) your whole onCreate() method in com.masked.app.mainjava. It sounds like you didn't initialize your media player.
If anyone else is having trouble with crash reports, this is an AMAZING way to get better feedback on Android is this project: http://code.google.com/p/acra/
EDIT:
Your problem is almost certainly caused by the a codec issue (your device cannot play the given resource due to its filetype/format). What type of sound file is it?
You can get around your issue by changing this block:
if (startsoundint == 1){
MediaPlayer mp = MediaPlayer.create(Mainjava.this, R.raw.start);
if (mp != null) // null check
{
mp.start();
}
}
And yes, this means it's probably not a new bug, unless you changed the sound file.

Widget Exception on Power On

My app has a home screen widget. When I power on the phone (from off, not sleep) I get a fatal exception.
04-06 14:33:59.739: ERROR/AndroidRuntime(271): java.lang.RuntimeException: Unable to instantiate receiver com.mytest.myapp.AppWidget: java.lang.ClassNotFoundException: com.mytest.myapp.AppWidget in loader dalvik.system.PathClassLoader[/data/app/com.mytest.myapp-2.apk]
04-06 14:33:59.832: ERROR/AndroidRuntime(269): Caused by: java.lang.ClassNotFoundException: com.mytest.myapp.AppWidget in loader dalvik.system.PathClassLoader[/data/app/com.mytest.myapp-2.apk]
If I click the app to start it again, it works fine. Any idea on what is happening?
It would be useful to see the Manifest.mf, just in case there's a typo lurking in there.
Failing that, the only explanation that leaps to mind is that the phone is trying to launch the app before /data is mounted. Can you reproduce in the emulator?
Phil Lello

Categories

Resources