我是Google Maps V2认证地图实施的新手,
但是我根据https://developers.google.com/maps/documentation/android/start中的步骤进行了整合,但是我遇到了崩溃。
使用logcat
显示白色屏幕片刻并崩溃06-01 04:07:03.459: E/AndroidRuntime(1199): FATAL EXCEPTION: main
06-01 04:07:03.459: E/AndroidRuntime(1199): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.sample.map_test/com.sample.map_test.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.os.Looper.loop(Looper.java:130)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-01 04:07:03.459: E/AndroidRuntime(1199): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 04:07:03.459: E/AndroidRuntime(1199): at java.lang.reflect.Method.invoke(Method.java:507)
06-01 04:07:03.459: E/AndroidRuntime(1199): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-01 04:07:03.459: E/AndroidRuntime(1199): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-01 04:07:03.459: E/AndroidRuntime(1199): at dalvik.system.NativeStart.main(Native Method)
06-01 04:07:03.459: E/AndroidRuntime(1199): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class fragment
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-01 04:07:03.459: E/AndroidRuntime(1199): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:209)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.Activity.setContentView(Activity.java:1657)
06-01 04:07:03.459: E/AndroidRuntime(1199): at com.sample.map_test.MainActivity.onCreate(MainActivity.java:12)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-01 04:07:03.459: E/AndroidRuntime(1199): ... 11 more
06-01 04:07:03.459: E/AndroidRuntime(1199): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
06-01 04:07:03.459: E/AndroidRuntime(1199): ... 19 more
06-01 04:07:03.459: E/AndroidRuntime(1199): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment in loader dalvik.system.PathClassLoader[/data/app/com.sample.map_test-1.apk]
06-01 04:07:03.459: E/AndroidRuntime(1199): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-01 04:07:03.459: E/AndroidRuntime(1199): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-01 04:07:03.459: E/AndroidRuntime(1199): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-01 04:07:03.459: E/AndroidRuntime(1199): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
06-01 04:07:03.459: E/AndroidRuntime(1199): ... 22 more
当我检查包含的库文件google-play-services_lib
时,它显示红色的十字符号。我删除并再次添加它,同时添加它显示绿色刻度标记,一旦我保存并关闭它变成红十字。
为什么我无法添加此库项目?请建议我哪里出错了。
为了您的信息,为了测试,我尝试了以下,
我也尝试过处理google-play-services_lib
项目库jar文件并粘贴到我的项目libs文件夹中,但我仍然遇到同样的崩溃。
欢迎任何相关的答案。在此先感谢。
答案 0 :(得分:0)
您不应将jar复制到libs文件夹中。你应该在你的android项目中引用库项目。
将库项目导入工作区进入eclipse。图书馆项目可以在
找到 <android-sdk-folder>/extras/google/google_play_services/libproject/google-play-services_lib library project .
点击文件&gt;导入,选择Android&gt;将现有的Android代码导入Workspace,并浏览工作区导入库项目。您可以检查它是否是库项目。右键单击库项目。转到属性。点击左侧面板上的Android。您将看到Is Library已选中。
右键单击您的项目。转到属性。选择android。单击添加。浏览并添加库项目。清理并构建