0

I have a question about transferring data through Intent() to a MapView.

String coorx = temptItem.getCordx();
String coory = temptItem.getCordy();
goTomap.putExtra("x", coorx);
goTomap.putExtra("y", coory);
System.out.println(coorx);
startActivity(goTomap);

where goTomap is my Intent: goTomap = new Intent(this,MyMap.class); But after I click on the ListView to go to another class, it gives:

java.lang.RuntimeException: Unable to start activity .....
java.lang.NullPointerException

My manifest is from many sample codes around the web.

<activity android:name=".MyMap" 
            android:label="location">
           <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>

Anyway to solve this?

EDIT Added MyMap

package com.nyp.stud084839L.isbconnects;

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.os.Bundle;

public class MyMap extends MapActivity{
    private MapView mapView;
    private MapController mc;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.map_view);
        String coordinates[] = {"40.747778", "-73.985556"};
        double lat = Double.parseDouble(coordinates[0]);
        double lng = Double.parseDouble(coordinates[1]);

        GeoPoint p = new GeoPoint(
            (int) (lat * 1E6), 
            (int) (lng * 1E6));

        mc = mapView.getController();
        mc.animateTo(p);
        mc.setZoom(17); 
        mapView.invalidate();        
    }

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

}
4
  • and NullPointerException in wich line are throwed? maybe is not your activity instead any other line... Commented Feb 1, 2011 at 13:08
  • java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nyp.stud084839L.isbconnects/com.nyp.stud084839L.isbconnects.MyMap}: java.lang.NullPointerException Commented Feb 1, 2011 at 13:20
  • Please post more of the exception from your LogCat file and perhaps the source code of MyMap.class. Also, your manifest file looks a bit suspect as it shows the MyMap activity as the default - so your intent would launch another MyMapp activity. Commented Feb 1, 2011 at 13:23
  • It appears to be this that caused the error mc = mapView.getController(); I will update my question with my class Commented Feb 1, 2011 at 13:29

1 Answer 1

1

From what you've said in comments, your local variable mapView must be null (i.e. findViewById() is failing) and therefore the problem is that your layout/main.xml does not contain a MapView with the attribute android:id="@+id/map_view".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.