当前位置: 首页 > 知识库问答 >
问题:

无法启动activity ComponentInfo:二进制XML文件行#6:inflating类片段时出错

齐乐
2023-03-14

试图进入一个整合了谷歌地图的新活动,我从标题中得到了一个错误。上述活动课:

package com.ict.edu.rs.imenik;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

public class MapViewActivity extends FragmentActivity implements
    OnMapLongClickListener {

private GoogleMap googleMap;
private String lat, lng;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_view);
    if (googleMap == null) {

        googleMap = ((SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map)).getMap();

        if (googleMap == null) {
            Toast.makeText(getApplicationContext(), "Mapa nije kreirana!",
                    Toast.LENGTH_SHORT).show();
        }
    }

    googleMap.getUiSettings().setMyLocationButtonEnabled(true);
    googleMap.setMyLocationEnabled(true);
    googleMap.setOnMapLongClickListener(this);

}

@Override
public void onMapLongClick(final LatLng arg0) {
    AlertDialog.Builder builder = new AlertDialog.Builder(
            MapViewActivity.this);
    builder.setCancelable(true);
    builder.setTitle("Alert");
    builder.setMessage("Sacuvaj lokaciju?");
    builder.setInverseBackgroundForced(true);
    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            lat = "" + arg0.latitude;
            lng = "" + arg0.longitude;
            dialog.dismiss();
            Intent returnIntent = new Intent();
            returnIntent.putExtra("lat", lat);
            returnIntent.putExtra("lng", lng);
            setResult(RESULT_OK, returnIntent);
            finish();
        }
    });

    builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    AlertDialog alert = builder.create();
    alert.show();
}
}

以及相应的XML文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:scrollingCache="false" />

</FrameLayout>

这也是货单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ict.edu.rs.imenik"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="5089000" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyD1-NOAbX37THopQ9IKWV84dbTdysqGndc" />

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.ict.edu.rs.imenik.NoviKontakt" />
    <activity android:name="com.ict.edu.rs.imenik.IzmeniKontakt" />
    <activity android:name="com.ict.edu.rs.imenik.MapViewActivity" />
    <activity android:name="com.ict.edu.rs.imenik.RezultatPretrage" />
</application>

</manifest>

我在这里处理什么?

共有1个答案

尉迟越
2023-03-14

将XML更改为

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">

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

</RelativeLayout>
 类似资料: