运行Google Map API时出现InflateException

时间:2012-08-08 09:04:14

标签: android google-maps

我在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;
}

我的班级

{{1}}

1 个答案:

答案 0 :(得分:0)

你有没有给出你的谷歌地图API密钥?如果是,你可能还没有使用MapActivity扩展你的课程以取代活动。当你使用map时,你需要在活动中扩展MapActivity

有关详细信息,请查看此问题 android hellomap example giving exception