I'm developing a Wear application and wanted to show a Confirmation message to the user after a click.
I know that for Wear dedicated tools like ConfirmationActivity exist, but after trying to show it I receive a Null Pointer Exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
This is the offending code causing the NPE:
Intent intent = new Intent(ApplicationContext, typeof(ConfirmationActivity));
intent.PutExtra(ConfirmationActivity.ExtraAnimationType, ConfirmationActivity.SuccessAnimation);
StartActivity(intent);
Here's the application manifest (notice I declared ConfirmationActivity):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="xx.xxxxxxx.xxxxxxx" android:installLocation="auto">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="28" />
<uses-feature android:name="android.hardware.type.watch" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
<application android:allowBackup="true" android:icon="#mipmap/ic_launcher" android:label="#string/app_name" android:supportsRtl="true" android:theme="#android:style/Theme.DeviceDefault">
<uses-library android:name="com.google.android.wearable" android:required="true" />
<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data android:name="com.google.android.wearable.standalone" android:value="true" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" 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="${applicationId}" />
</intent-filter>
</receiver>
<receiver android:name=".BootReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<activity android:name="android.support.wearable.activity.ConfirmationActivity"></activity>
</application>
</manifest>
This is the stack trace:
07-02 07:41:50.270 E/AndroidRuntime( 6760): java.lang.RuntimeException: Unable to start activity ComponentInfo{xx.xxxxxxxx.xxxxxx/android.support.wearable.activity.ConfirmationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.-wrap11(Unknown Source:0)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.os.Handler.dispatchMessage(Handler.java:105)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.os.Looper.loop(Looper.java:164)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.main(ActivityThread.java:6541)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at java.lang.reflect.Method.invoke(Native Method)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
07-02 07:41:50.270 E/AndroidRuntime( 6760): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageDrawable(android.graphics.drawable.Drawable)' on a null object reference
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.updateImageView(ConfirmationOverlay.java:302)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.updateOverlayView(ConfirmationOverlay.java:249)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.view.ConfirmationOverlay.showOn(ConfirmationOverlay.java:194)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.support.wearable.activity.ConfirmationActivity.onCreate(ConfirmationActivity.java:79)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.Activity.performCreate(Activity.java:6975)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
07-02 07:41:50.270 E/AndroidRuntime( 6760): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
I think your context is incorrect. Try this:
Intent intent = new Intent (this, typeof(ConfirmationActivity))
.SetFlags (ActivityFlags.NewTask | ActivityFlags.NoAnimation)
.PutExtra (ConfirmationActivity.ExtraAnimationType, ConfirmationActivity.SuccessAnimation)
.PutExtra (ConfirmationActivity.ExtraMessage, "Message Goes Here");
StartActivity (intent);
And if that doesn't work either, you might have to override the Intent handling function too, as you can see here and here.
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 have made functional changes in my ionic app and tested in browser by ionic serve. Everything went fine and proceeded for ionic build. So it returned me below error.
I:\myprojects\fizion>ionic package info 30
id │ 30
status │ FAILED
platform │ android
mode │ debug
started │ Jul 30th, 2017 10:32:28
output:
ANDROID_HOME=/opt/android-sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /opt/android-sdk/tools/templates/gradle/wrapper
I am not sure whose Android SDK it is suggesting to upgrade. Mine or ionic cloud's ?
Ok, I tried to upgrade my android studio SDK and then other problem started. Then I have issued below command to propogate the new changes to the android.
cordova prepare android
I have built the .apk file and launched in phone. It crashed, so tried in emulator and got the below error.
--------- beginning of crash
07-30 12:18:53.350 3040-3040/com.ionicframework.fizion233539 E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ionicframework.fizion233539, PID: 3040
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ionicframework.fizion233539/com.ionicframework.fizion233539.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.ionicframework.fizion233539.MainActivity" on path: DexPathList[[zip file "/data/app/com.ionicframework.fizion233539-1/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.fizion233539-1/lib/x86_64, /vendor/lib64, /system/lib64]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.ionicframework.fizion233539.MainActivity" on path: DexPathList[[zip file "/data/app/com.ionicframework.fizion233539-1/base.apk"],nativeLibraryDirectories=[/data/app/com.ionicframework.fizion233539-1/lib/x86_64, /vendor/lib64, /system/lib64]]
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.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.NoClassDefFoundError: com.ionicframework.fizion233539.MainActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:338)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 13 more
Suppressed: java.lang.ClassNotFoundException: com.ionicframework.fizion233539.MainActivity
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
07-30 12:18:53.352 1584-1596/system_process W/ActivityManager: Force finishing activity com.ionicframework.fizion233539/.MainActivity
my manifest file:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="com.ionicframework.fizion233539" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<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_NETWORK_STATE" />
<application android:hardwareAccelerated="true" android:icon="#drawable/icon" android:label="#string/app_name" android:supportsRtl="true">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="#string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="#android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
<intent-filter android:label="#string/launcher_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="https://hs7pj.app.goo.gl/" android:scheme="https" />
</intent-filter>
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="fizion-f4286.firebaseapp.com" android:path="/__/auth/callback" android:scheme="https" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
<uses-feature android:name="android.hardware.location.gps" />
</manifest>
I have been going through many SO posts and tried many but nothing worked out.
I am happy to share my android studio screenshots for configurations. I am sure this is due to upgrade of android studio but where to crack it.
Could someone guide me I am blocked.
My android studio was showing me warning mentioned in the below post. So I ignored it. But that is the culprit and fixed the issue.
Android, IntelliJ Idea, changing module type
Using these configurations I did add sugar orm to my project, but my application stopped unfortunately by this error :
FATAL EXCEPTION: main
Process: gigacycle.geoaudiotag, PID: 22760
java.lang.RuntimeException: Unable to instantiate application com.orm.SugarApp: java.lang.ClassNotFoundException: Didn't find class "com.orm.SugarApp" on path: DexPathList[[zip file "/data/app/gigacycle.geoaudiotag-1/base.apk"],nativeLibraryDirectories=[/data/app/gigacycle.geoaudiotag-1/lib/arm, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:676)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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 "com.orm.SugarApp" on path: DexPathList[[zip file "/data/app/gigacycle.geoaudiotag-1/base.apk"],nativeLibraryDirectories=[/data/app/gigacycle.geoaudiotag-1/lib/arm, /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:1004)
at android.app.LoadedApk.makeApplication(LoadedApk.java:666)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6289)
at android.app.ActivityThread.access$1800(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1860)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
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)
Suppressed: java.lang.ClassNotFoundException: com.orm.SugarApp
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
This is my Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gigacycle.geoaudiotag">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
android:name="com.orm.SugarApp">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
<meta-data android:name="DATABASE" android:value="geoaudiotagdb.db" />
<meta-data android:name="VERSION" android:value="2" />
<meta-data android:name="QUERY_LOG" android:value="true" />
<meta-data android:name="DOMAIN_PACKAGE_NAME" android:value="gigacycle.geoaudiotag"/>
<activity
android:name="gigacycle.geoaudiotag.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
also this line is compiling successfully!
compile 'com.github.satyan:sugar:1.4'
I don't know why this fatal error occurred? where is my mistake?
Sync gradle and build.
Just download the package does not generate com.orm.SugarApp. Gradle sync will generate the class and before syncing, it appears as lint error in AndroidManifest.
Unfortunately this cannot be captured as compiler error and results in runtime error as you get.
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.
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.