我的Android应用程序出现问题。
我正在尝试在两个标签之间切换,其中一个标签应显示地图。 但线程正在退出未捕获的异常。 当我调试我得到这个:
二进制XML文件行#7:错误类膨胀 com.google.android.gms.maps.MapView
我查看了所有可能的谷歌搜索结果,但我找不到答案。
这是我的地图类
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文件mapview_tab
<?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>
这个依赖项我添加到pom.xml文件
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>google-play-services</artifactId>
<version>16.0.0</version>
<scope>provided</scope>
</dependency>
以下是我的清单中的一些重要代码着作:
<permission android:name="com.example.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" >
</uses-feature>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="dsvfdfsAdsfasdfcvdasVGJfsDSSDzcfdASWD"/>
<uses-library android:name="com.google.android.maps"/>
googleplaylibraray jar文件是&#34;非运行时maven dependenciy&#34;
我希望有人能帮助我!
基恩问候,
垃圾
------ EDIT -----------
logcat的:
VFY:无法解析静态字段1308(MapAttrs) LCOM /谷歌/机器人/克/ R $设置样式;
VFY:在0x000e
处替换opocode 0x62关闭VM
threadid = 1:线程退出,未捕获异常(group = 0x41b81700)
编辑2 -----------------------------
新XML文件
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
MAP CLASS
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;
}
}
logcat的:
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)
点击MAP TAB后,这是我得到的最后一个,然后我的手机冻结了。
答案 0 :(得分:0)
发布设备版本也可能是因为扩展了片段类,如果你使用的设备用于测试较低版本,你可以扩展
public class MapFragment extends
android.support.v4.app.Fragment
答案 1 :(得分:0)
点击此链接https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2 --- Google指南
方式: - &gt;使用mapfragment而不是mapview ....
更新
对于Map类
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;
}
}