Android 单击标记时未显示AlertDialog

Android 单击标记时未显示AlertDialog,android,google-maps,google-maps-markers,Android,Google Maps,Google Maps Markers,*我已经创建了警报对话框,在单击标记后显示该对话框 *但当我单击marker时,它会使应用程序崩溃。 *有什么问题吗?我还缺什么吗? 提前感谢 googleMap.setOnMarkerClickListener(new OnMarkerClickListener() { @SuppressWarnings("deprecation") @Override public boolean onMarkerClick(Mark

*我已经创建了警报对话框,在单击标记后显示该对话框
*但当我单击marker时,它会使应用程序崩溃。
*有什么问题吗?我还缺什么吗?
提前感谢

googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {

            @SuppressWarnings("deprecation")
            @Override
            public boolean onMarkerClick(Marker marker) {

                showAlertDialog();

                return false;

            }


        });



private void showAlertDialog() {

    AlertDialog alert = new AlertDialog.Builder(
            getBaseContext()).create();

    alert.setTitle("Location Selected");
    alert.setMessage("Add this Location to your");
    alert.setButton("Places",

            new DialogInterface.OnClickListener() {

                //code goes here
            });
    alert.setButton("Activities",
            new DialogInterface.OnClickListener() {

                //code goes here
                }

            });
    alert.show();

}
试一试

而不是

AlertDialog alert = new AlertDialog.Builder(getBaseContext()).create();

你能发布你的logcat代码片段以了解更多信息吗?据说不能从AlertDialog转换到AlertDialog.Builder
AlertDialog alert = new AlertDialog.Builder(getBaseContext()).create();
@SuppressWarnings("deprecation")
    void showAlertDialog(final LatLng markerPosition) {

        AlertDialog alertDialog = new AlertDialog.Builder(GoogleMapViewer.this)
                .create();

        alertDialog.setTitle("Location Selected");

        alertDialog.setMessage("Add this Location to your");

        alertDialog.setButton2("Places", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(),
                        "You clicked on Places", Toast.LENGTH_SHORT).show();
            }
        });

        alertDialog.setButton3("Activities",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent act_intent = new Intent();
                        act_intent.setClass(GoogleMapViewer.this,
                                addActivities.class);
                        act_intent.putExtra("username", savedUserName);
                        act_intent
                                .putExtra("latitude", markerPosition.latitude);
                        act_intent.putExtra("longitude",
                                markerPosition.longitude);
                        startActivity(act_intent);

                    }
                });

        alertDialog.show();
    }