0

我见过几十个类似的问题,但似乎都没有解决我的问题。我有一个使用谷歌地图 v2(以前使用的 v1)的应用程序。我导入了 google-play-services 和 android-support-v4,并创建了一个扩展 SupportFragment 的活动(也尝试了片段)。我将所有权限和我的密钥添加到清单中,并在我的布局文件夹中创建了一个片段来定义地图。但是,每次我在我的活动中对我的片段调用 setContentView 时,我的应用程序都会崩溃。我在这个活动中导入了 android.support.v4.app.FragmentActivity 和 android.support.v4.app.Fragment,但是在尝试给片段充气时出错。下面列出了 logcat 日志。提前致谢!

public class ManualCheckInMapActivity extends android.support.v4.app.FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_fragment);
         }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"    
    android:orientation="vertical" >     
    <fragment        
        android:name="com.google.android.gms.maps.SupportMapFragment"             
        android:id="@+id/map"        
        android:layout_width="match_parent"        
        android:layout_height="match_parent" />
</LinearLayout>

致命例外:主要

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.safehouse.onguardianmobile/com.safehouse.onguardianmobile.ManualCheckInMapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4627)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
    at android.app.Activity.setContentView(Activity.java:1647)
    at com.safehouse.onguardianmobile.ManualCheckInMapActivity.onCreate(ManualCheckInMapActivity.java:40)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
    ... 11 more
Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
    at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
    at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
    ... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/system/framework/com.google.android.maps.jar:/data/app/com.safehouse.onguardianmobile-2.apk]
    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
    at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
    ... 23 more

更新:我尝试清理项目,但现在出现此错误。我还是新手,不,也许我没有正确添加库?

构建过程中发生错误。

Errors running builder 'Android Package Builder' on project 'google-play-services_lib'.
Problems encountered while deleting resources.
Could not delete 'C:\Users\Travis\workspace\google-play-services_lib\bin\google-play-services_lib.jar'.
Problems encountered while deleting files.
Could not delete: C:\workspace\google-play-services_lib\bin\google-play-services_lib.jar.
Problems encountered while deleting resources.
Could not delete 'C:\workspace\google-play-services_lib\bin\google-play-services_lib.jar'.
Problems encountered while deleting files.
Could not delete: C:\Users\Travis\workspace\google-play-services_lib\bin\google-play-services_lib.jar.
4

0 回答 0