0

在 Eclipse 中运行一个关于 Google Map API 的项目时,我遇到了一个问题。我有一个新的 Google API 项目,AVD 目标是 Google API。但是Android.view.InflateException,扁平化类存在错误com.google.android.maps.MapView。布局有问题吗?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/jindu"
        />
    <EditText 
        android:id="@+id/et1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="116.46"
        />

</LinearLayout>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/weidu"
        />
    <EditText 
        android:id="@+id/et2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="16.46"
        />
    <Button 
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/select"
        />
</LinearLayout>
<com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:enabled="true"
    android:apiKey="AIzaSyBtMrZJRGm32jIFRxmpgKf3WTqR6AHmkj8"
    />

 </LinearLayout>

我的主要文件

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Map"
        android:label="@string/title_activity_map" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <uses-library android:name="com.google.android.maps" />

</application>

我的课

EditText et1;
EditText et2;
Button button1;
MapView mapView;
MapController mapController;

double jindu = 116.46;
double weidu = 39.92;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    et1 = (EditText) this.findViewById(R.id.et1);
    et2 = (EditText) this.findViewById(R.id.et2);
    button1 = (Button) this.findViewById(R.id.button1);
    mapView = (MapView) this.findViewById(R.id.mapView);
    mapController = mapView.getController();        
    setGeoPoint();
    button1.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            jindu = Double.parseDouble(et1.getText().toString());
            weidu = Double.parseDouble(et2.getText().toString());
            setGeoPoint();
        }

    });
}

private void setGeoPoint() {
    GeoPoint gp = new GeoPoint((int)(jindu*1E6),(int)(weidu*1E6));
    mapController.animateTo(gp);
    mapController.setZoom(18);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
4

1 回答 1

0

你有没有给你的谷歌地图 API 密钥?如果是的话,你可能没有用 MapActivity 代替活动扩展你的类。当您使用地图时,您需要扩展 MapActivity 代替活动

有关更多详细信息,请检查此问题 android hellomap 示例给出异常

于 2012-08-08T09:15:01.720 回答