<uses-library android:name="com.google.android.maps" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
这些都在AndroidManifest.xml中加上了。
模拟器使用的是google apis 7的,在模拟器上,显示地图、缩放、添加标记等都已经测试通过完全可用了。
将apk拷到手机上时,一打开就显示“....已意外停止。请重试。”.使用eclipse调试模式连接手机进行调试时,发现异常是:
08-15 22:47:52.093: ERROR/AndroidRuntime(4753): Uncaught handler: thread main exiting due to uncaught exception
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.android.learn.GoogleMap/com.android.learn.GoogleMap.GoogleMap}: java.lang.ClassNotFoundException: com.android.learn.GoogleMap.GoogleMap in loader [email protected]
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2497)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread.access$2200(ActivityThread.java:126)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.os.Looper.loop(Looper.java:123)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread.main(ActivityThread.java:4595)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at java.lang.reflect.Method.invoke(Method.java:521)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at dalvik.system.NativeStart.main(Native Method)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): Caused by: java.lang.ClassNotFoundException: com.android.learn.GoogleMap.GoogleMap in loader [email protected]
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
08-15 22:47:52.283: ERROR/AndroidRuntime(4753): ... 11 more
手机上应该是支持google api的,因为我安装了邻讯、飘信等内嵌地图的程序,打开他们的apk看过里面的AndroidManifest.xml,也是有<uses-library android:name="com.google.android.maps" />这句的,而且res/layout中的一些xml也是使用的<com.google.android.maps.MapView
所以我认为手机也是支持google api的。但是不知道为什么同一个程序在模拟器上可以运行,在手机上却会报错。在网上搜索相似问题时,发现别人都是能打开程序,但是显示不出来地图,跟我的又不一样。
有谁遇到过或者知道是怎么回事的,麻烦告知一下。谢谢