0

我正在创建一个包含三个主要活动的项目(我们称它们为活动 1、2 和 3)。在活动 1 中,我额外传递了我的捆绑包中的数字。

newActivity.putExtra("LAT", getText(R.string.LAT1));
newActivity.putExtra("LNG", getText(R.string.LNG1));

然后,在第二个中,我得到这样的:

     double Lata;
    double Lnga;

//in onCreate..
        Bundle extras = getIntent().getExtras();

        Lata = extras.getDouble("LAT");
        Lnga = extras.getDouble("LNG");

然后,我将它们传递给第三个活动,如下所示:

newActivity.putExtra("LAT",Lata);
newActivity.putExtra("LNG",Lnga);

最后,在第三个活动中:

public class mapview extends MapActivity
{
 @Override  
 public void onCreate(Bundle savedInstanceState)
 {
 super.onCreate(savedInstanceState);
 requestWindowFeature(Window.FEATURE_NO_TITLE);

 setContentView(R.layout.map);

 MapView mapView = (MapView) findViewById(R.id.mapview);
 mapView.setBuiltInZoomControls(true);
 //mapView.setSatellite(true);
 //mapView.setStreetView(true);
 List<Overlay> mapOverlays = mapView.getOverlays();
  Drawable drawable = this.getResources().getDrawable(R.drawable.pin);
 HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);

 Bundle extras = getIntent().getExtras();
final double Latc = extras.getDouble("LAT");
 final double Lngc = extras.getDouble("LNG");
Integer txt_map = extras.getInt("MAP_NAME");





 TextView mapname=(TextView)findViewById(R.id.museum_address_name);
 mapname.setText(getText(txt_map));

 Double lat = Double.valueOf(Latc*1E6);

    Double lng = Double.valueOf(Lngc*1E6);

    //---------------------------------------------------
    GeoPoint center = new GeoPoint(Double.valueOf(Latc*1E6).intValue(), Double.valueOf(Lngc*1E6).intValue());
    MapController controller = mapView.getController();
        controller.setCenter(center);
    controller.setZoom(15);
    //---------------------------------------------------

    GeoPoint point = new GeoPoint(lat.intValue(), lng.intValue());
 OverlayItem overlayitem = new OverlayItem(point, "", "");


 itemizedoverlay.addOverlay(overlayitem);

 mapOverlays.add(itemizedoverlay);
 }
 @Override
 protected boolean isRouteDisplayed()
 {
 return false;
 }
}

结果在南美洲的某个地方,但我的经纬度都在欧洲……我做错了什么?我试图修复它超过 2 小时……:(

编辑

04-25 23:58:19.001: W/KeyCharacterMap(3746): No keyboard for id 0
04-25 23:58:19.081: W/KeyCharacterMap(3746): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
04-25 23:58:22.461: W/Bundle(3746): Key LAT expected Double but value was a java.lang.Integer.  The default value 0.0 was returned.
04-25 23:58:22.481: W/Bundle(3746): Attempt to cast generated internal exception:
04-25 23:58:22.481: W/Bundle(3746): java.lang.ClassCastException: java.lang.Integer
04-25 23:58:22.481: W/Bundle(3746):     at android.os.Bundle.getDouble(Bundle.java:1017)
04-25 23:58:22.481: W/Bundle(3746):     at android.os.Bundle.getDouble(Bundle.java:1000)
04-25 23:58:22.481: W/Bundle(3746):     at kostas.menu.athensmuseums.museum_item.onCreate(museum_item.java:39)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-25 23:58:22.481: W/Bundle(3746):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 23:58:22.481: W/Bundle(3746):     at android.os.Looper.loop(Looper.java:123)
04-25 23:58:22.481: W/Bundle(3746):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 23:58:22.481: W/Bundle(3746):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:58:22.481: W/Bundle(3746):     at java.lang.reflect.Method.invoke(Method.java:521)
04-25 23:58:22.481: W/Bundle(3746):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 23:58:22.481: W/Bundle(3746):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 23:58:22.481: W/Bundle(3746):     at dalvik.system.NativeStart.main(Native Method)
04-25 23:58:22.481: W/Bundle(3746): Key LNG expected Double but value was a java.lang.Integer.  The default value 0.0 was returned.
04-25 23:58:22.491: W/Bundle(3746): Attempt to cast generated internal exception:
04-25 23:58:22.491: W/Bundle(3746): java.lang.ClassCastException: java.lang.Integer
04-25 23:58:22.491: W/Bundle(3746):     at android.os.Bundle.getDouble(Bundle.java:1017)
04-25 23:58:22.491: W/Bundle(3746):     at android.os.Bundle.getDouble(Bundle.java:1000)
04-25 23:58:22.491: W/Bundle(3746):     at kostas.menu.athensmuseums.museum_item.onCreate(museum_item.java:40)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-25 23:58:22.491: W/Bundle(3746):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-25 23:58:22.491: W/Bundle(3746):     at android.os.Looper.loop(Looper.java:123)
04-25 23:58:22.491: W/Bundle(3746):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-25 23:58:22.491: W/Bundle(3746):     at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:58:22.491: W/Bundle(3746):     at java.lang.reflect.Method.invoke(Method.java:521)
04-25 23:58:22.491: W/Bundle(3746):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-25 23:58:22.491: W/Bundle(3746):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-25 23:58:22.491: W/Bundle(3746):     at dalvik.system.NativeStart.main(Native Method)
04-25 23:58:24.251: W/MapActivity(3746): Recycling dispatcher com.google.googlenav.datarequest.DataRequestDispatcher@44ec4318
4

1 回答 1

0

我怀疑getText返回 aString或 aCharSequence所以你将一个字符串放入包中但将其作为双精度读取。相反,请确保先将其转换为双精度:

newActivity.putExtra("LAT", Double.parseDouble(getText(R.string.LAT1)));
newActivity.putExtra("LNG", Double.parseDouble(getText(R.string.LNG1)));

这是假设您已经正确验证了您TextView的 s 确实包含有效的双精度。

于 2012-04-25T20:55:23.293 回答