Android 将LatLng发送到下一个活动,并将其值放入编辑文本框中

Android 将LatLng发送到下一个活动,并将其值放入编辑文本框中,android,google-maps,Android,Google Maps,我已经设置了我的项目,这样我就可以在地图上单击n,它会添加一个标记,现在我想尝试将该标记的坐标发送到下一个活动中,这样我就可以填写有关该位置的更多详细信息,并将其发送到我的数据库中。如果有人能提供帮助,我将不胜感激。但是,每次我尝试将LatLn坐标发送到下一个活动时,我都会收到一个错误: java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.homescreen/com.homescreen.Cl

我已经设置了我的项目,这样我就可以在地图上单击n,它会添加一个标记,现在我想尝试将该标记的坐标发送到下一个活动中,这样我就可以填写有关该位置的更多详细信息,并将其发送到我的数据库中。如果有人能提供帮助,我将不胜感激。但是,每次我尝试将LatLn坐标发送到下一个活动时,我都会收到一个错误:

java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.homescreen/com.homescreen.ClubForm}: java.lang.NullPointerException
以下是我的代码,用于将标记添加到地图,效果良好:

public class Map extends ActionBarActivity{

private GoogleMap myMap;
String c_name;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

    myMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();
    // Initializing
    // Getting reference to Button
    Button btnDraw = (Button) findViewById(R.id.btn_route);
    Button btnAddClub = (Button) findViewById(R.id.btn_add_club);

    btnDraw.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // if club button is pressed start ClubLogin Activity
            Intent i = new Intent(getApplicationContext(), DrawRoute.class);

            startActivity(i);
        }
    });


     LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     Criteria criteria = new Criteria();

     Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
     if (location != null)
     {

         myMap.setMyLocationEnabled(true);
         myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                 new LatLng(location.getLatitude(), location.getLongitude()), 13));

         CameraPosition cameraPosition = new CameraPosition.Builder()
         .target(new LatLng(location.getLatitude(), location.getLongitude()))      // Sets the center of the map to location user
         .zoom(6)                   // Sets the zoom
         .bearing(0)                // Sets the orientation of the camera to east
         .tilt(40)                   // Sets the tilt of the camera to 30 degrees
         .build();                   // Creates a CameraPosition from the builder
     myMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
     }
     btnAddClub.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
             // Perform action on click
             myMap.setOnMapClickListener(new OnMapClickListener() {
                 @Override
                 public void onMapClick(LatLng latlng) {
                     addMarker(latlng, c_name);
                     Intent c = new Intent(getApplicationContext(), ClubForm.class);
                     c.putExtra("latlng", latlng);
                    startActivity(c);
                 }
             });
         }
     });

}

// Adding marker on the GoogleMaps
private void addMarker(LatLng latlng, String c_name) {
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latlng);
    markerOptions.title(c_name);
    markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.club_marker));
    myMap.addMarker(markerOptions);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

下面是表单的下一个活动,我试图将latlng坐标发送到编辑文本框中:

public class ClubForm extends ActionBarActivity {

String c_name;
String c_email;
String c_address;
String c_phno;
String c_size;
InputStream is = null;
String result = null;
String line = null;
int code;

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

    Bundle bundle = getIntent().getExtras();

    if(bundle != null){

        LatLng = new GeoPoint((int)(bundle.getDouble("lat") / 1E6),(int)(bundle.getDouble("long")/1E6));
        animateToCurrentPoint(currentGeoPoint);

    }


    final EditText e_name = (EditText) findViewById(R.id.editbox2);
    final EditText e_email = (EditText) findViewById(R.id.editbox7);
    final EditText e_address = (EditText) findViewById(R.id.editbox3);
    final EditText e_phno = (EditText) findViewById(R.id.editbox6);
    final EditText e_size = (EditText) findViewById(R.id.editbox4);
    final EditText e_latlng = (EditText) findViewById(R.id.editbox8);
    Button submit = (Button) findViewById(R.id.btn_submit);

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            c_name = e_name.getText().toString();
            c_email = e_email.getText().toString();
            c_address = e_address.getText().toString();
            c_phno = e_phno.getText().toString();
            c_size = e_size.getText().toString();
            //latlng = e_latlng.getText().toString();
            //submit();
        }
    });
}

/*public void submit() {
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("c_name", c_name));
    nameValuePairs.add(new BasicNameValuePair("c_email", c_email));
    nameValuePairs.add(new BasicNameValuePair("c_address", c_address));
    nameValuePairs.add(new BasicNameValuePair("c_phno", c_phno));
    nameValuePairs.add(new BasicNameValuePair("c_size", c_size));
    nameValuePairs.add(new BasicNameValuePair("latlng", latlng));

    try {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("purposely wrong");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.e("pass 1", "connection success ");
    } catch (Exception e) {
        Log.e("Fail 1", e.toString());
        Toast.makeText(getApplicationContext(), "Invalid IP Address",
                Toast.LENGTH_LONG).show();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        result = sb.toString();
        Log.e("pass 2", "connection success ");
    } catch (Exception e) {
        Log.e("Fail 2", e.toString());
    }

    try {
        JSONObject json_data = new JSONObject(result);
        code = (json_data.getInt("code"));

        if (code == 1) {
            Toast.makeText(getBaseContext(), "Inserted Successfully",
                    Toast.LENGTH_SHORT).show();
        } else {
            Toast.makeText(getBaseContext(), "Sorry, Try Again",
                    Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        Log.e("Fail 3", e.toString());
    }
}

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

LatLng=新的GeoPointintbundle.getDoublelat/ 1E6,intbundle.getDoublelong/1E6

NPE,因为捆绑包不包含lat和long键

有意发送LatLng对象。使用Intent.getParcelable从onCreate方法中接收的Intent获取:

Intent intent = getIntent().getExtras();
if(intent !=null)
 LatLng latlng = intent.getParcelable("latlng");

所以我必须使用LatLng=new geopoint intbundle.getDoublelat/1E6,intbundle.getDoublelong/1E6;在我的地图类代码中?@SqlNoob:使用latlng.latitude和latlng.longitude获取coordinates@SqlNoob:like GeoPoint GeoPoint=new GeoPoint intlatlng.lation*1E6,intlatlng.longitude*1E6;Intent-Intent=getIntent.getExtras;不能有getExtras,因为它不是捆绑包?