1

MapView当我尝试创建一个片段以保存它崩溃说找不到类时,我正在尝试创建一个包含 a 的布局以及其他项目(是的,我确实导入了谷歌播放服务库)

错误:

03-08 13:48:01.593: E/AndroidRuntime(30614): android.view.InflateException: Binary XML file line #7: Error inflating class com.google.android.gms.maps.MapView
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.ecm2.mobilemap.fragments.CurrentIncidentMapFrag.onCreateView(CurrentIncidentMapFrag.java:16)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.Fragment.performCreateView(Fragment.java:1695)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.BackStackRecord.run(BackStackRecord.java:682)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Handler.handleCallback(Handler.java:725)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.os.Looper.loop(Looper.java:137)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.app.ActivityThread.main(ActivityThread.java:5041)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Method.invoke(Method.java:511)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at dalvik.system.NativeStart.main(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614): Caused by: java.lang.reflect.InvocationTargetException
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Constructor.constructNative(Native Method)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-08 13:48:01.593: E/AndroidRuntime(30614):    ... 20 more
03-08 13:48:01.593: E/AndroidRuntime(30614): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
03-08 13:48:01.593: E/AndroidRuntime(30614):    at com.google.android.gms.maps.MapView.<init>(Unknown Source)

布局xml:(布局会改变我只是想让地图先工作)

<?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" >

<com.google.android.gms.maps.MapView
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

和我的片段

public class CurrentIncidentMapFrag extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle saved){
    View v = inflater.inflate(R.layout.current_incident_mapping_layout,container,false);

    return v;
}

}

我知道有一个地图片段,但我想要的不仅仅是一张地图,而且我不希望它占据片段中的整个视图,所以一个包含所有内容的视图片段是我唯一的选择。

我怎样才能让地图显示出来?

4

2 回答 2

1

您忘记输入您的 api 密钥

<com.google.android.maps.MapView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:clickable="true"
    android:apiKey="***"
/>

并确保您在清单中有这一行

<uses-library android:name="com.google.android.maps" />

编辑

如果您删除 onDestroyView() 中的所有嵌套片段,您可以解决此问题。不知道这是否是一个适当的解决方案。

    public void onDestroyView() {
        super.onDestroyView(); 
        Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));  
        FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        ft.remove(fragment);
        ft.commit();
}

并像往常一样在 onCreateView() 中膨胀它们

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    return inflater.inflate(R.layout.map, container, false);
}
于 2013-03-08T19:28:24.797 回答
0

我真的不明白,你是说你想使用 Google Map API V2。但您正在尝试使用作为 Google Map API V1 对象的 MapView 对象。如果你想创建一个带有版本的地图到这里:

关联

这是我写的关于创建 Google Map API V2 的帖子。

于 2013-03-08T19:42:12.463 回答