Android 映射片段类不会消失!通货膨胀异常
我的android应用程序有问题 我试图在两个选项卡之间切换,其中一个选项卡应该显示地图。 但线程正在退出,但未捕获到异常。 调试时,我得到以下结果: 二进制XML文件行#7:膨胀类时出错 com.google.android.gms.maps.MapView 我查看了所有可能的谷歌搜索结果,但找不到答案 这是我的地图课Android 映射片段类不会消失!通货膨胀异常,android,google-maps,maven,maps,Android,Google Maps,Maven,Maps,我的android应用程序有问题 我试图在两个选项卡之间切换,其中一个选项卡应该显示地图。 但线程正在退出,但未捕获到异常。 调试时,我得到以下结果: 二进制XML文件行#7:膨胀类时出错 com.google.android.gms.maps.MapView 我查看了所有可能的谷歌搜索结果,但找不到答案 这是我的地图课 public class MapFragment extends Fragment { MapView mapView; GoogleMap map;
public class MapFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapview_tab, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.mapview);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(47.223065, 8.816511), 10);
map.animateCamera(cameraUpdate);
return v;
}
}
这是我的xml文件“地图视图”选项卡
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.gms.maps.MapView android:id="@+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
日志:
05-13 14:47:50.189: D/AbsListView(16376): unregisterIRListener() is called
05-13 14:47:51.179: D/AbsListView(16376): onDetachedFromWindow
05-13 14:48:20.009: D/AndroidRuntime(16376): Shutting down VM
05-13 14:48:20.009: W/dalvikvm(16376): threadid=1: thread exiting with uncaught exception (group=0x41b81700)
单击地图选项卡后,这是我最后一次看到的,然后我的手机会冻结。发布设备版本也可能是由于extends fragment类,如果您使用设备测试较低版本,则需要扩展
public class MapFragment extends
android.support.v4.app.Fragment
检查此链接
---谷歌指南
方法:-->使用mapfragmet而不是mapview
更新
地图类
public class MapFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapview_tab, container, false);
return v;
}
}
请发布你的日志。我是否有可能在google play库中遇到问题?它不工作是因为它没有正确导入?请在导入google play服务后尝试。不是这样。我的另一个选项卡也从Fragment扩展而来,它工作得很好。拥有一个安道尔ID为4.3的星系s3可能是我做错了吗?我更改了xml文件,就像上面描述的链接一样。但是如何更改我的.java文件呢?你能指导我吗?@tritrotrash链接中的每一样东西我的类都是从FRAGMENT扩展而来的,所以它不是一个活动。没关系,只需在你的fragments类中膨胀mapfragments xml文件,请粘贴准确的logcat错误,并根据新的实现更新问题。没有它,我无能为力。
public class MapFragment extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapview_tab, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.MapView);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(47.223065, 8.816511), 10);
map.animateCamera(cameraUpdate);
return v;
}
}
05-13 14:47:50.189: D/AbsListView(16376): unregisterIRListener() is called
05-13 14:47:51.179: D/AbsListView(16376): onDetachedFromWindow
05-13 14:48:20.009: D/AndroidRuntime(16376): Shutting down VM
05-13 14:48:20.009: W/dalvikvm(16376): threadid=1: thread exiting with uncaught exception (group=0x41b81700)
public class MapFragment extends
android.support.v4.app.Fragment
public class MapFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.mapview_tab, container, false);
return v;
}
}