Ankit Gomkale
Ankit Gomkale

Reputation: 724

android application error

my xml code is:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.google.android.maps.MapView
                 android:id="@+id/mapView"

                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:enable="true"
                 android:clickable="true"
                 android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
                 />
</RelativeLayout>

and manifest is:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.google.haha"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

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


    <application android:icon="@drawable/icon" android:label="@string/app_name">
      <uses-library android:name="com.google.android.maps"/>  
        <activity android:name=".NewActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>

And this is main code:

package com.google.haha;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.os.Bundle;

public class NewActivity extends MapActivity {
    /** Called when the activity is first created. */

    MapController mControl;
    GeoPoint GeoP;
    MapView mapV;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

       mapV=(MapView)findViewById(R.id.mapView);
       mapV.displayZoomControls(true);
       mapV.setBuiltInZoomControls(true);
       double lat=21.00;
       double longi=79.00;
       GeoP=new GeoPoint((int)(lat*1E6),(int)(longi*1E6));

       mControl=mapV.getController();
       mControl.animateTo(GeoP);
       mControl.setZoom(12);


    }

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

Everything is fine but I am getting error an on line:

mapV=(MapView)findViewById(R.id.mapView);

id field is not recognised.

Upvotes: 0

Views: 683

Answers (2)

Helio
Helio

Reputation: 1

<com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    **android:enable="true"** MUST BE android:enabled="true"
    android:clickable="true"
    android:apiKey="0THdCiXY7jaJ9Br1ZQahFE4Lu1xTv1hAiVJBvxQ"
    />
</RelativeLayout>

Upvotes: 0

Houcine
Houcine

Reputation: 24181

try to clean and rebuild your project, because that problem comes up sometimes on Eclipse IDE , the id of your MapView is not recognised on your R.java file :

Project ==> Clean ==> Choose your Project and Clic OK

Upvotes: 2

Related Questions