Android-单击自定义列表适配器中的行中的按钮时启动MapActivity

Android-单击自定义列表适配器中的行中的按钮时启动MapActivity,android,android-intent,mapactivity,Android,Android Intent,Mapactivity,我有一个应用程序,它有一个自定义的列表适配器。该列表有三个部分:图像、文本和按钮 单击一行时,我会执行一个活动开始 单击按钮时,我希望启动另一个活动,但这是一个MapActivity 这两项活动都必须携带通过意向书中的附加程序传递的信息 第一个(单击行)活动工作正常 第二种方法仅在开始常规活动时有效 当我尝试启动MapActivity时,应用程序崩溃 下面的代码位于自定义适配器类中,在OnClick方法中作为参数/参数接收的视图是一个按钮(这就是我使用getParent的原因) 如果有什么不

我有一个应用程序,它有一个自定义的
列表适配器
。该列表有三个部分:图像、文本和按钮

  • 单击一行时,我会执行一个
    活动
    开始
  • 单击按钮时,我希望启动另一个活动,但这是一个
    MapActivity
  • 这两项活动都必须携带通过意向书中的附加程序传递的信息
  • 第一个(单击行)活动工作正常
  • 第二种方法仅在开始常规活动时有效
  • 当我尝试启动
    MapActivity
    时,应用程序崩溃
  • 下面的代码位于自定义适配器类中,在
    OnClick
    方法中作为参数/参数接收的视图是一个按钮(这就是我使用
    getParent
    的原因)
如果有什么不清楚的地方,请告诉我,我会尽力回答



以下是错误日志:

11-01 18:32:18.374: W/dalvikvm(14162): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
11-01 18:32:18.393: E/AndroidRuntime(14162): FATAL EXCEPTION: main
11-01 18:32:18.393: E/AndroidRuntime(14162): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.turiston/com.example.turiston.GoogleMaps}: java.lang.NullPointerException
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.os.Looper.loop(Looper.java:123)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread.main(ActivityThread.java:4627)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at java.lang.reflect.Method.invokeNative(Native Method)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at java.lang.reflect.Method.invoke(Method.java:521)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at dalvik.system.NativeStart.main(Native Method)
11-01 18:32:18.393: E/AndroidRuntime(14162): Caused by: java.lang.NullPointerException
11-01 18:32:18.393: E/AndroidRuntime(14162):    at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:301)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at java.lang.Float.parseFloat(Float.java:291)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at com.example.turiston.GoogleMaps.onCreate(GoogleMaps.java:37)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-01 18:32:18.393: E/AndroidRuntime(14162):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-01 18:32:18.393: E/AndroidRuntime(14162):    ... 11 more

这是
GoogleMaps.java的
OnCreate
方法

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

    // Obtains the coordinates from the place from the previous Activity
    Bundle extras = getIntent().getExtras();
    float latitude; // = 19.2373f;
    float longitude; // = 68.82634f;

    // Variables to store the strings from the database
    String lat_coordinate;
    String lon_coordinate;

    // Assigns the values from the previous Activity to the two variables
    lat_coordinate = extras.getString("Latitude");
    lon_coordinate = extras.getString("Longitude");

    latitude = Float.parseFloat(lat_coordinate);
    longitude = Float.parseFloat(lon_coordinate);

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

    // Enables zoom controls for the map
    mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(
            R.drawable.androidmarker);

    MapsItemizedOverlay itemizedoverlay = new MapsItemizedOverlay(drawable,
            this);

    // Creates a GeoPoint to be used for the location of the place on the
    // map
    GeoPoint point = new GeoPoint((int) (latitude * 1E6),
            (int) (longitude * 1E6));

    // If you click on the Android guy it displays the following message
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!",
            "I'm in San Juan!");
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
}
@覆盖
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u谷歌地图);
//从上一个活动的位置获取坐标
Bundle extras=getIntent().getExtras();
浮动纬度;/=19.2373f;
浮动经度;/=68.82634f;
//变量来存储数据库中的字符串
串坐标;
弦长坐标;
//将上一个活动中的值分配给两个变量
纬度坐标=extras.getString(“纬度”);
lon_坐标=extras.getString(“经度”);
纬度=Float.parseFloat(纬度坐标);
经度=Float.parseFloat(经度坐标);
MapView MapView=(MapView)findViewById(R.id.MapView);
//启用地图的缩放控件
mapView.SetBuilTinZoomControl(真);
List mapOverlays=mapView.getOverlays();
Drawable Drawable=this.getResources().getDrawable(
R.可拉拔式标记);
MapsItemizedOverlay itemizedoverlay=新的MapsItemizedOverlay(可绘制,
这),;
//创建一个地质点,用于场地在地图上的位置
//地图
地质点=新的地质点((int)(纬度*1E6),
(int)(经度*1E6));
//如果你点击安卓的家伙,它会显示以下消息
OverlayItem OverlayItem=新的OverlayItem(点“Hola,Mundo!”),
“我在圣胡安!”;
itemizedoverlay.addOverlay(overlayitem);
添加(itemizedoverlay);
}
不要使用“android.intent.action.GOOGLEMAPS”作为操作名称。创建一个包含你的包名的应用程序,这样它就不会与任何其他应用程序发生冲突

似乎坐标没有到达谷歌地图活动。 将Log.d()放在活动开始前的第一个活动中,并在“latitude=Float.parseFloat(lat_坐标);”之前的第二个活动中


顺便说一句,您在第一个活动中使用常量作为附加名称,在第二个活动中使用字符串文字,很容易出错。始终使用常量。

请向我们提供错误日志。错误发生在文件GoogleMaps.java的第37行。您可以发布GoogleMaps.java onCreate方法吗
位于com.example.turiston.GoogleMaps.onCreate(GoogleMaps.java:37)
当我从常规活动中打开GoogleMaps.java时,它会工作。我想知道这是否与适配器或列表视图有关。GoogleMaps.java中哪一行是37?第37行是:latitude=Float.parseFloat(lat_坐标);谢谢我终于修好了。这是一个简单但容易出错的错误。字符串“lat_坐标”和“lon_坐标”都是空的,因为我用来传递附加值的标记是不同的。我用的是“latitud”和“longitud”(常量DB_FIELD_LAT和DB_FIELD_LON),而我的队友,他负责另一个类(GoogleMaps.java)却用了“latitude”和“longitud”(有趣的是,它们在不同的语言中是相同的)。我只是将代码中的标记名改为那些GoogleMaps.java接收到的,就像这样:String LAT=“Latitude”字符串LON=“Longitude”,并将putExtras更改为:intent.putExtra(LAT,LAT);intent.putExtra(LON,LON);最后,我编写了如下意图:intent intent=new intent(parentView.getContext(),GoogleMaps.class);谢谢大家!P.S.由于声誉问题,我还不能回答我自己的问题,但我想让你们知道问题已经解决了。正如我所说,常量是你们的朋友;-)
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_google_maps);

    // Obtains the coordinates from the place from the previous Activity
    Bundle extras = getIntent().getExtras();
    float latitude; // = 19.2373f;
    float longitude; // = 68.82634f;

    // Variables to store the strings from the database
    String lat_coordinate;
    String lon_coordinate;

    // Assigns the values from the previous Activity to the two variables
    lat_coordinate = extras.getString("Latitude");
    lon_coordinate = extras.getString("Longitude");

    latitude = Float.parseFloat(lat_coordinate);
    longitude = Float.parseFloat(lon_coordinate);

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

    // Enables zoom controls for the map
    mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(
            R.drawable.androidmarker);

    MapsItemizedOverlay itemizedoverlay = new MapsItemizedOverlay(drawable,
            this);

    // Creates a GeoPoint to be used for the location of the place on the
    // map
    GeoPoint point = new GeoPoint((int) (latitude * 1E6),
            (int) (longitude * 1E6));

    // If you click on the Android guy it displays the following message
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!",
            "I'm in San Juan!");
    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
}