2
votes

i am trying to run sample code of Google map API v2 iam getting following errors can any one help me

04-23 08:54:23.178: E/Trace(1703): error opening trace file: No such file or directory (2)
04-23 08:54:24.489: W/dalvikvm(1703): VFY: unable to resolve static field 859 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-23 08:54:24.489: D/dalvikvm(1703): VFY: replacing opcode 0x62 at 0x000e
04-23 08:54:24.508: D/AndroidRuntime(1703): Shutting down VM
04-23 08:54:24.508: W/dalvikvm(1703): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-23 08:54:24.538: E/AndroidRuntime(1703): FATAL EXCEPTION: main
04-23 08:54:24.538: E/AndroidRuntime(1703): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.Activity.setContentView(Activity.java:1881)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.swetha.googlemap.MainActivity.onCreate(MainActivity.java:17)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.Activity.performCreate(Activity.java:5104)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.os.Looper.loop(Looper.java:137)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at java.lang.reflect.Method.invokeNative(Native Method)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at java.lang.reflect.Method.invoke(Method.java:511)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-23 08:54:24.538: E/AndroidRuntime(1703):     at dalvik.system.NativeStart.main(Native Method)
04-23 08:59:24.708: I/Process(1703): Sending signal. PID: 1703 SIG: 9

main activity

public class MainActivity extends FragmentActivity { GoogleMap map; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); map=((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();

map.setMapType(GoogleMap.MAP_TYPE_NORMAL);

2
have you linked google play library correctly?Ranco
Have you imported google play services ? check the accepted answerflexdroid
From your error log it indicates that you have not included the Google Play Service library into your application. So just add that library in your application after exporting from the android sdk.GrIsHu
Post your code of MainActivity.java file.GrIsHu
i have imported googleplay serviceuser2310370

2 Answers

3
votes

Import google play services, check this link to know how to import it.

And change the line map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)) .getMap(); to map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) .getMap();

0
votes

If you are extending from FragmentActivity means you are developing the app for target below 11. You should use the SupportMapFragment.

SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

See my blog posts i have tried to summarize all there is needed to build an App with Google Maps API V2 for Android.

  1. Solution to Problems with Maps API V2(using google_play_services_lib).
  2. Creating an Android App with Maps API V2 for minSDK=8 (Android 2.2 Froyo).
  3. Creating an Android App with Maps API V2 for minSDK=11 (Android 3.0 HoneyComb).