1
當我添加地圖片段時:「錯誤充氣類片段」嘗試添加地圖V2片段activity_main
<fragment 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"
android:id="@+id/map"
tools:context=".MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"/>
到activity_main.xml中我得到這個錯誤:
FATAL EXCEPTION: main
Process: com.example.koba.ogloszenia, PID: 3073
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.koba.ogloszenia/com.example.koba.ogloszenia.MainActivity}: android.view.InflateException: Binary XML file line #120: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
...
我MainActivity.java:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment MapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
MapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap Map) {
mMap = Map;
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}
我AndroidManife st.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.koba.ogloszenia">
<uses-permission android:name="android.Manifest.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.Manifest.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.Manifest.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MY_API_KEY"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
我已經包含在depedencies
- com.google.android.gms:發揮服務:9.2.1 和
- com.google.android。 gms:play-services-maps:9.2.1
我也在SDK Tools中檢查過「Google Play服務」。
我也看了類似的帖子,但是這並沒有解決我的問題。
預先感謝您。