【问题标题】:Unable to start activity ComponentInfo: Binary XML file line #6: Error inflating class fragment无法启动活动 ComponentInfo:二进制 XML 文件第 6 行:膨胀类片段时出错
【发布时间】:2014-10-04 23:05:15
【问题描述】:

试图进入一个集成了 Google 地图的新活动,我从标题中收到错误消息。上述活动类:

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>

我在这里处理什么?

【问题讨论】:

  • 我认为您缺少指定 v2 中使用的 opengl。不过,我不确定这是否是问题所在。 Srecno :)

标签: java android google-maps android-fragments


【解决方案1】:

将您的 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多