简体   繁体   中英

GCM Demo client on Android, error with “Unable to instantiate activity”

I'm trying to use the demo client app of GCM provided by Google: http://developer.android.com/google/gcm/client.html

However I'm unable to run it, because my app crashes with "Unable to instantiate activity" error.

Full thing here:

> 05-06 12:09:10.748: I/SELinux(20458): Function: selinux_android_load_priority [0], There is no sepolicy file.
> 05-06 12:09:10.748: I/SELinux(20458):  
> 05-06 12:09:10.748: I/SELinux(20458): Function: selinux_android_load_priority , loading version is VE=SEPF_GT-I9505_4.4.2_0010
> 05-06 12:09:10.748: I/SELinux(20458):  
> 05-06 12:09:10.748: I/SELinux(20458):  
> 05-06 12:09:10.748: I/SELinux(20458): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
> 05-06 12:09:10.748: D/dalvikvm(20458): Late-enabling CheckJNI
> 05-06 12:09:11.139: D/AndroidRuntime(20458): Shutting down VM
> 05-06 12:09:11.139: W/dalvikvm(20458): threadid=1: thread exiting with uncaught exception (group=0x418cada0)
> 05-06 12:09:11.139: E/AndroidRuntime(20458): FATAL EXCEPTION: main
> 05-06 12:09:11.139: E/AndroidRuntime(20458): Process: com.google.android.gcm.demo.app, PID: 20458
> 05-06 12:09:11.139: E/AndroidRuntime(20458): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.google.android.gcm.demo.app/com.google.android.gcm.demo.app.DemoActivity}: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gcm.demo.app.DemoActivity" on path: DexPathList[[zip file "/data/app/com.google.android.gcm.demo.app-13.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gcm.demo.app-13, /vendor/lib, /system/lib]]
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread.access$900(ActivityThread.java:161)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.os.Handler.dispatchMessage(Handler.java:102)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.os.Looper.loop(Looper.java:157)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread.main(ActivityThread.java:5356)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at java.lang.reflect.Method.invokeNative(Native Method)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at java.lang.reflect.Method.invoke(Method.java:515)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at dalvik.system.NativeStart.main(Native Method)
> 05-06 12:09:11.139: E/AndroidRuntime(20458): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gcm.demo.app.DemoActivity" on path: DexPathList[[zip file "/data/app/com.google.android.gcm.demo.app-13.apk"],nativeLibraryDirectories=[/data/app-lib/com.google.android.gcm.demo.app-13, /vendor/lib, /system/lib]]
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
> 05-06 12:09:11.139: E/AndroidRuntime(20458):     ... 11 more

The code itself should work fine I belive. The only thing that involved "me" is adding libs.

I had to add Google Play Services and "v4 support library" (as it was written in Readme). I downloaded play services via Android SDK Manager, imported the project and than added to my main thing with Properties->Android->Add Library.

With App-compat (which probably is the problem) I tried two methods: - Same as above with google resources - or copying jar to libs and then RMB->BuildPath->Add to buildpath. I made sure to check in Java build path "Android Private Libraries" and/or app-compat.jar

And of course I did multiple project/cleans.

I would gladly provide any fragment of my code, however except my API key I didn't modify anything, so it is as in the Google example. And - I'm using Eclipse.

I ran into the same problem. To achieve that the example works, you need to complete three steps:

  • Add google play services lib (did)
  • Add android support v4 library (did)
  • And finally note that the source code in this examples are in java/com/google/android/gcm/demo/app/ directory, but when eclipse compiles the source code not search in this path for source code. For solving this you have two options:

    • Create a package named com.google.android.gcm.demo.app into src folder (right click -> New -> Package) and then move the three source code java files to src directory (just drag and drop). Finally clean the project (go to Project -> Clean). Note that src directory is by default in the java build path.

      or

    • Add the path of source code to java build path. Go to project properties -> Java Build Path -> Add Folder... -> now select Java directory -> OK. I attach a screenshot to help http://i.stack.imgur.com/yQoLC.png

Sorry for my English. I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM