Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Android API v2 - Sample Code crashes

I'm trying to get the sample code of Android 'Google Maps Android API v2' working. I get the project built without errors. However, when I try to run the app on my Galaxy Nexus (connected with usb to my laptop), the app crashes immediately.

  • I filled in my own Maps API Key at the AndroidManifest.xml
  • I built against Android 4.1.2

This is the logging:

Unable to resolve superclass of Lcom/example/mapdemo/BasicMapActivity; (66)  Link of class 'Lcom/example/mapdemo/BasicMapActivity;' failed  Could not find class 'com.example.mapdemo.BasicMapActivity', referenced from method com.example.mapdemo.MainActivity.<clinit>  VFY: unable to resolve const-class 108 (Lcom/example/mapdemo/BasicMapActivity;) in Lcom/example/mapdemo/MainActivity;  VFY: replacing opcode 0x1c at 0x000d  Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lcom/example/mapdemo/MainActivity;  Class init failed in newInstance call (Lcom/example/mapdemo/MainActivity;)  Shutting down VM  threadid=1: thread exiting with uncaught exception (group=0x41ac9930)  FATAL EXCEPTION: main  java.lang.ExceptionInInitializerError at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.Instrumentation.newActivity(Instrumentation.java:1054) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5039) 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:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method)  Caused by: java.lang.NoClassDefFoundError: com.example.mapdemo.BasicMapActivity at com.example.mapdemo.MainActivity.<clinit>(MainActivity.java:97) ... 15 more 

Does anybody have a hint how to solve this or what I might be doing wrong?

like image 617
alexx Avatar asked Dec 05 '12 22:12

alexx


People also ask

Why does Google Maps keep crashing Android?

Clear the app's cache & data On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find the Maps app. After you select the app, storage & cache options should be available.

Why is Google Maps crashing so much?

If the Google Maps app didn't start correctly or ran into a minor glitch, then it might cause the app to crash. In such cases, merely restarting the app should do the trick. Long-press on the Google Maps icon and select the App info. That'll take you to App Settings.

Is Google Maps API free for Android?

You won't be charged until your usage exceeds $200 in a month. Note that the Maps Embed API, Maps SDK for Android, and Maps SDK for iOS currently have no usage limits and are at no charge (usage of the API or SDKs is not applied against your $200 monthly credit).


2 Answers

Follow the crib sheet very, very carefully:
https://docs.google.com/document/pub?id=19nQzvKP-CVLd7_VrpwnHfl-AE9fjbJySowONZZtNHzw

In particular, I think you need to:

  • Import the actual source for the "google-play-services_lib" project and link it as an Android library.
    • Do this through Project -> Properties -> Android -> Library, Add -> google-play-services_lib (you can right click on your project and choose Properties, then select Android).
    • Do not add it as a dependent Project through the "Java Build Path" for your project, that didn't work for me.
  • Add the google-play-services.jar and android-support-v4.jar into a "libs" folder in the sample project, and add them as "External External JARs" in "Build Path -> Configure Build Path -> Libraries".

I found this second step was necessary as I was hitting the exact same error as you when trying to use the sample code. The first step was necessary to avoid a NoClassDefFoundError in com.google.android.gms.R$styleable in my real project.

I also needed to do a Clean build and Uninstall the app from the device (from an earlier test attempt) before the sample code worked.

like image 171
Dan J Avatar answered Oct 05 '22 23:10

Dan J


Follow next sample code instructions by google.

Skip on "4" section, and follow below instructions:

  • Add new folder to your project named "libs"
  • Copy google-play-services.jar form:

    "android-sdk-folder\extras\google\google_play_services\libproject\google-play-services_lib\libs"

    to "libs" folder --> right click on this jar in this folder --> Build path --> Add to build path.

  • Copy android-support-v4.jar form:

    "android-sdk-folder\extras\android\support\v4"

    to "libs" folder --> right click on this jar in this folder --> Build path --> Add to build path.

Where "android-sdk-folder" usually looks like: "C:\Users\User_Name\android-sdks"

like image 23
David Avatar answered Oct 05 '22 22:10

David