![](/img/trans.png)
[英]android.view.InflateException: Binary XML file line #6: Error inflating class com.google.android.gms.maps.MapView
[英]Error inflating class com.google.android.gms.maps.MapView
我如下更改了代碼;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.harita);
}
catch (Exception e)
{
e.printStackTrace();
}
boolean kontrol = true;
Bundle bundle = getIntent().getExtras();
String enlem = "";
if(bundle.getString("enlem") != null)
{
enlem = bundle.getString("enlem");
}
else
{
kontrol = false;
}
String boylam = "";
if(bundle.getString("boylam") != null)
{
boylam = bundle.getString("boylam");
}
else
{
kontrol = false;
}
String baslik = "";
if(bundle.getString("baslik") != null)
{
baslik = bundle.getString("baslik");
}
else
{
kontrol = false;
}
if (kontrol == true) {
GoogleMap map = ((MapFragment) getFragmentManager().findFragmentById(R.id.haritaFragment)).getMap();
LatLng position = new LatLng(Double.parseDouble(enlem),Double.parseDouble(boylam));
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(position, 13));
map.addMarker(new MarkerOptions().title(baslik).snippet("Baslik").position(position));
}
}
和我的布局;
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/haritaFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
我還將這段代碼添加到我的Manifest.xml中。
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
它的值類似於strings.xml中的值;
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="google_play_services_version">4030500</integer>
</resources>
我更改了密碼。 現在,我在setContentView try catch塊上收到類似“二進制XML文件第2行:錯誤誇大類片段”的錯誤。
可能的問題:
您可能需要封裝您的片段。
您的API等級應超過8
您應該從Project-> Properties-> Android添加庫
如果您在同一工作區中運行Map Demo,則建議將其刪除。
該問題似乎與設備無關,但請嘗試在設備(而非仿真器)上進行測試
使用以下布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</LinearLayout>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.