0

I got a question while running a project in eclipse about Google Map API. I have a new Google API project and the AVD target is Google APIs. But there is Android.view.InflateException, error in flating class com.google.android.maps.MapView. Is there something wrong in the layout?

<?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>

my mainfest file

<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>

my class

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;
}
kingpei
  • 3
  • 2

1 Answers1

0

have u given ur GoogleMap API key currectly?and if yes than may u have not extends ur class with MapActivity inplace of acitivty. whenver u are using map u need to extend MapActivity inplace of activity

for more detail check this issue android hellomap example giving exception

Community
  • 1
  • 1
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74
  • yes,you got it,i find i didn't extends MapActivity.But then it appears this:08-09 03:21:44.391: E/ActivityThread(219): Failed to find provider info for com.google.settings 08-09 03:21:44.422: E/ActivityThread(219): Failed to find provider info for com.google.settings 08-09 03:21:44.451: E/ActivityThread(219): Failed to find provider info for com.google.settings 08-09 03:21:45.211: I/MapActivity(219): Handling network change notification:CONNECTED 08-09 03:21:45.211: E/MapActivity(219): Couldn't get connection factory client – kingpei Aug 09 '12 at 03:29
  • There is still something wrong,the map doesn't appear.The exception is as above. – kingpei Aug 09 '12 at 04:56
  • have u given `` in ur manifest file? if not than put it just before you close ur u close ur application tag like this:`` – Aamirkhan Aug 09 '12 at 05:08
  • i have,i add my mainfest file in my question right now, u can have a look. – kingpei Aug 09 '12 at 06:31
  • when i wanted to register a google map api key by ordinary steps yesterday,i found i can't.google has been updated, and i found a key for browser apps in https://code.google.com/apis/console after i signed up my Gmail account, i'm not sure is it works. – kingpei Aug 09 '12 at 08:17