I'm in the process of making my own Android app and along the way discovered GCM (Google Cloud Messaging). I followed the following tutorial exactly: http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/
The good news is that almost everything works properly, except that every time I send a push notification, the App force closes on the device. I don't think anything is wrong with the Eclipse project and I'm running Android 4.2.2 on my device. There are no compilation errors. It is driving me nuts that I can't figure out why the App keeps force closing.
The code is exactly the same as what is listed in the above link. For reference, here is my logcat:
E/AndroidRuntime( 7261): FATAL EXCEPTION: main
E/AndroidRuntime( 7261): java.lang.RuntimeException: Unable to instantiate receiver com.javapapers.android.GcmBroadcastReceiver: java.lang.ClassNotFoundException: Didn't find class "com.javapapers.android.GcmBroadcastReceiver" on path: /data/app/com.javapapers.android-1.apk
E/AndroidRuntime( 7261): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2428)
E/AndroidRuntime( 7261): at android.app.ActivityThread.access$1600(ActivityThread.java:151)
E/AndroidRuntime( 7261): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1358)
E/AndroidRuntime( 7261): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 7261): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 7261): at android.app.ActivityThread.main(ActivityThread.java:5285)
E/AndroidRuntime( 7261): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 7261): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 7261): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
E/AndroidRuntime( 7261): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
E/AndroidRuntime( 7261): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
E/AndroidRuntime( 7261): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 7261): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.javapapers.android.GcmBroadcastReceiver" on path: /data/app/com.javapapers.android-1.apk
E/AndroidRuntime( 7261): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
E/AndroidRuntime( 7261): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 7261): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 7261): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2423)
E/AndroidRuntime( 7261): ... 11 more
W/GTalkService( 1430): [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE pkg=com.javapapers.android (has extras) }
My manifest looks like the following:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="com.javapapers.android.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.javapapers.android.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="16" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".RegisterActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.javapapers.android.MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
<receiver
android:name=".GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.javapapers.android" />
</intent-filter>
</receiver>
<service android:name=".GCMNotificationIntentService" />
I'm at my wits end trying to figure out what is wrong, so any and all help is appreciated.
What package is your GcmBroadcastReceiver located in?
When using the . prefix, like you did when declaring .GcmBroadcastReceiver, the . translates to your package name. So unless GcmBroadcastReceiver is located in com.javapapers.android then it will not work.
Even I faced same concern. Right Click project go to -> build Path -> Config Build path -> order and export -> check mark Android dependencies (google paly services.jar) shift to top. Now Clean and build and run your application.
Related
I am trying to implement ImageCropper inside my app. On Android I need to add some things to the Manifest according to the documentation but I can not make it work... This is my Manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.memories">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<application>
<activity>
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
But this crashes with this error:
E/AndroidRuntime( 9936): at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime( 9936): at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime( 9936): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9936): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime( 9936): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime( 9936): Caused by: java.lang.IllegalStateException: Reply already submitted
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:155)
E/AndroidRuntime( 9936): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:238)
E/AndroidRuntime( 9936): at vn.hunghd.flutter.plugins.imagecropper.ImageCropperDelegate.onActivityResult(ImageCropperDelegate.java:106)
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult(FlutterEngineConnectionRegistry.java:739)
E/AndroidRuntime( 9936): at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult(FlutterEngineConnectionRegistry.java:426)
E/AndroidRuntime( 9936): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult(FlutterActivityAndFragmentDelegate.java:677)
E/AndroidRuntime( 9936): at io.flutter.embedding.android.FlutterActivity.onActivityResult(FlutterActivity.java:624)
E/AndroidRuntime( 9936): at android.app.Activity.dispatchActivityResult(Activity.java:8310)
E/AndroidRuntime( 9936): at android.app.ActivityThread.deliverResults(ActivityThread.java:5008)
E/AndroidRuntime( 9936): ... 11 more
I/Process ( 9936): Sending signal. PID: 9936 SIG: 9
What am I missing here? What is the correct way to add the activities?
Try this code in you AndroidMainfest. May be you are missing Launcher Activity in application level.
<application
android:name="io.flutter.app.FlutterApplication"
android:label="example"
android:icon="#mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="#style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"/>
</application>
aaah... I changed the wrong manifest... it is important to change the main:
/android/app/src/main/AndroidManifest.xml
Everything is working fine now.
i am running one android application in which i am using ActionBar but from supported library for android 2.2
i have added two external jar file as a support libraries
android-support-v7-appcompact.jar
android-support-v13.jar
but when i run the sample in my device i getting following runtime error
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.example.android.navigationdrawerexample/com.example.android.navigationdrawerexample.NavMainActivity}:
java.lang.ClassNotFoundException:
com.example.android.navigationdrawerexample.NavMainActivity in loader
dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-1.apk]
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2703)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:143) at
android.app.ActivityThread.main(ActivityThread.java:4914) 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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) at
dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.example.android.navigationdrawerexample.NavMainActivity in loader dalvik.system.PathClassLoader[/data/app/com.example.android.navigationdrawerexample-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.newActivity(Instrumentation.java:1033)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2695)
here is the menifest file content
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.navigationdrawerexample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="7" />
<application
android:label="#string/app_name"
android:icon="#drawable/ic_launcher"
>
<activity android:name="NavMainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
order of jar files
You should not only look at errors but also at warnings (orange text color in eclipse logcat view). Dalvik class loading are often preceded by some interesting informations about why a class can't be loaded by the Dalvik, something like a super class not existing.
I defined following activity and intent filter in AndroidManifest.xml:
<application android:label="Test.SampleApp">
<activity android:name=".MainActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
Then I have an Activity set up as:
namespace Test.SampleApp
{
public class MainActivity : Activity
{
//....
}
}
The problem is that when I start the application, it cannot find the MainActivity class:
E/AndroidRuntime( 2047): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{Test.SampleApp/Test.SampleApp.MainActivity}: java.lang.ClassNotFoundException: Test.SampleApp.MainActivity
E/AndroidRuntime( 2047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
E/AndroidRuntime( 2047): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
E/AndroidRuntime( 2047): at android.app.ActivityThread.access$600(ActivityThread.java:123)
E/AndroidRuntime( 2047): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
E/AndroidRuntime( 2047): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2047): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 2047): at android.app.ActivityThread.main(ActivityThread.java:4424)
E/AndroidRuntime( 2047): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2047): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 2047): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime( 2047): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime( 2047): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2047): Caused by: java.lang.ClassNotFoundException: Test.SampleApp.MainActivity
E/AndroidRuntime( 2047): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime( 2047): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime( 2047): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime( 2047): at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
E/AndroidRuntime( 2047): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
E/AndroidRuntime( 2047): ... 11 more
W/ActivityManager( 162): Force finishing activity Test.SampleApp/.MainActivity
I'm guessing that I'm not referring to the Activity correctly in the manifest?
I've also tried using the 'Test.SampleApp.MainActivity' as a vlue for android:name,
but then the manifest is simply invalid and cannot be parsed.
I'm using Mono for Android, and now I'm wondering, the names used in the manifest,
do they relate to the C# namespaces or to something elsethat is specific to the Android platform?
Note: In the manifest I've also have package="Test.SampleApp"
Update: I added the "." in front of MainActivity but I'm still getting the exact same exception.
Based on the feedback (link) from #Triode I managed to figure it out:
The manifest in the sample application on github:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="mono.actionbarsherlocktest">
<uses-sdk android:minSdkVersion="7" />
<application android:label="Mono.ActionbarsherlockTest">
</application>
</manifest>
The package name here is lower case whereas my package name contained capitals.
Changing the package name to test.sampleapp and leaving everything else untouched solved the issue.
I hope this will help other monodroid users one day.
In general, do not write XML fragments for C#-provided activities. Instead, use custom attributes and let the build system worry about it for you.
namespace NamespaceName {
[Activity(
LaunchMode=Android.Content.PM.LaunchMode.SingleInstance,
StateNotNeeded=true)]
[IntentFilter (new[]{Android.Content.Intent.ActionMain},
Categories=new[]{Android.Content.Intent.CategoryHome, Android.Content.Intent.CategoryDefault})]
public class MainActivity : Activity {
// ...
}
}
The build system will generate the <activity/> element and use fully-qualified type names:
<activity android:name="namespacename.MainActivity"
android:launchMode="singleInstance"
android:stateNotNeeded="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
There are typically only two reasons to use XML fragments and not custom attributes:
The type doesn't exist in C#, e.g. your .apk contains Java activities.
You need to use XML attributes/elements that haven't been exposed via custom attributes.
I have built an application for a large multicultural festival in my city that kicks off on Saturday. I've tweaked a lot of bugs in the iPhone version and we are waiting for Apple to approve it. I have taken that perfected version as the basis for the Android version.
The Android version looks and works great. I can run it on my Samsung Galaxy S II by either "Run as Android Application" in Eclipse or by uploading it to a server and downloading it into the phone. I can also email the app to myself and it works, too. I submitted it to the Google Play store and once it got into the wild (this is advertised on billboards, buses, everywhere) it crashes the minute it is opened.
I'm not really sure how to troubleshoot this when it works fine on the device before publication. I read about how it has to do with the MainActivity activity name, but everything looks like it lines up.
Error 1 [ClassNotFoundException in PathClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader
dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1660)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama in loader dalvik.system.PathClassLoader[/data/app/com.honestapi.folk2011-1.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:251)
at java.lang.ClassLoader.loadClass(ClassLoader.java:548)
at java.lang.ClassLoader.loadClass(ClassLoader.java:508)
at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
Error 2 [ClassNotFoundException in BaseDexClassLoader.findClass()]:
java.lang.RuntimeException: Unable to instantiate activity
ComponentInfo{com.honestapi.folk2011/com.honestapi.folk2011.Folklorama}:
java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1894)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
at android.app.ActivityThread.access$600(ActivityThread.java:128)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4514)
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)
Caused by: java.lang.ClassNotFoundException: com.honestapi.folk2011.Folklorama
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:1027)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
Any help would be greatly appreciated! I am in quite the pickle.
Edit - Here is the AndroidManifest.xml from the bin folder
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />
<supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:resizeable="false" android:anyDensity="true" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:icon="#drawable/ic_launcher" android:label="#string/app_name" android:theme="#style/AppTheme">
<activity android:name=".MainActivity" android:label="#string/title_activity_main">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.CaptureActivity" android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name="com.google.zxing.client.android.encode.EncodeActivity" android:label="#string/share_name">
<intent-filter>
<action android:name="com.phonegap.plugins.barcodescanner.ENCODE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
It turned out my main Java file was named "MainActivity.java" but it was being called as "Folklorama.java" throughout the project files. I renamed the file to Folklorama.java.
I have an app with ~11k active installs for which I sometimes receive ClassNotFoundExceptions that I can't explain. They look like this:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{name.of.my.MainActivityClass}: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/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:4293)
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:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: name.of.my.MainActivityClass in loader dalvik.system.PathClassLoader[/mnt/asec/name.of.my-2/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)
... 11 more
I received some of these exceptions from users that updated my app (not only for the most recent version), so I think it is not a problem that is specific to some phones as the app worked for them before.
I got these exception reports for my main activity class, a receiver class and a BackupAgent class.
All of those classes are always instantiated directly from Android. My Manifest file looks like this:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="name.of.my"
android:versionCode="20"
android:versionName="1.10.2"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
<application android:icon="#drawable/icon" android:label="#string/app_name" android:backupAgent="name.of.my.OwnBackupAgent">
<activity android:name="name.of.my.MainActivityClass"
android:label="#string/app_name"
android:theme="#style/MyTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="name.of.my.OwnReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.RINGER_MODE_CHANGED" />
</intent-filter>
</receiver>
</application>
</manifest>
After searching the net for some hours, the most likely explanations I found are:
it might be related to moving the app to SD card while there are still some services running (but the android dev guide says that all services are canceled in this case, and it doesn't explain why my main activity class suddenly can't be found anymore)
the .apk might be corrupted after updating via the android market. Could this be true? If yes, what can I do against it - if not, what else might be the problem?