当前位置: 首页 > 知识库问答 >
问题:

Google map API v2

苏彭薄
2023-03-14

我正在尝试运行Google map API v2的示例代码,我得到了以下错误,任何一个可以帮助我吗

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

主activity

公共类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个答案

范建华
2023-03-14

如果您从FragmentActivity扩展,意味着您正在为低于11的target开发应用程序。您应该使用SupportMapFragment。

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

请看我的博客文章,我已经尝试总结了所有的需要,以构建一个应用程序谷歌地图APIV2为Android。

  1. 地图API V2问题的解决方案(使用google_play_services_lib)。
  2. 使用Maps API V2 for MinSDK=8创建Android应用程序(Android 2.2 Froyo)。
  3. 使用Maps API V2为MinSDK=11创建Android应用程序(Android 3.0蜂巢)。
董光霁
2023-03-14

导入google play服务,查看此链接了解如何导入。

并将行map=((MapFragment)getFragmentManager().FindFragmentById(r.id.map)).GetMap();更改为map=((SupportMapFragment)getSupportFragmentManager().FindFragmentById(r.id.map)).GetMap();

 类似资料:

相关问答

相关文章

相关阅读