谷歌地图查看"而在Android的例子&QUOT语境的问题; [英] Context problem in Android example "Google Map View"

查看:103
本文介绍了谷歌地图查看"而在Android的例子&QUOT语境的问题;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经试过落实谷歌地图视图教程对Android开发者网站,但我一直试图显示一个AlertDialog当我点击的叠加图像时遇到了一个问题。问题是,mContext调用时为空

I've tried to implement the Google Map View tutorial on the Android developer site, but I keep running into a problem when trying to display an AlertDialog when I click on the overlay image. The problem is that mContext is null when calling

AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);

在HelloItemizedOverlay的方法的onTap由于构造

in HelloItemizedOverlay's onTap method because the constructor

public HelloItemizedOverlay(Drawable defaultMarker, Context context) {
    super(boundCenterBottom(defaultMarker));
    mContext = context;
}

永远不会被调用(即我可以告诉),它初始化mContext。当我更换

is never called (that I can tell) which initializes mContext. When I replace

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable);

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, 
                this.getApplicationContext());

在HelloGoogleMaps的,以初始化上下文onCreate方法,我得到一个异常

in HelloGoogleMaps's onCreate method in order to initialize the context, I get an exception

android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null不是一个应用程序

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

当我尝试显示AlertDialog像这样:

when I try to display the AlertDialog like so:

dialog.show();

我认为这个教程已成功成千上万的人实现的,所以我在为什么没有其他人遇到了这个问题茫然......有我错过了本教程的一个重要步骤?

I assume this tutorial has been successfully implemented by thousands of people, so I'm at a loss why no one else has run into this problem... have I missed an important step from the tutorial?

推荐答案

我想你需要图形页面的上下文传递给HelloItemizedOverlay构造像这样:

I think you need to pass mapView's context to the HelloItemizedOverlay constructor like so:

HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, mapView.getContext());

很显然本教程的code样品中的错误。小错误,这样的疏漏都没有在参考文档屡见不鲜,尤其是对于大型项目像Android一样。

There is clearly an error in the tutorial's code sample. Small errors and omissions like this are not uncommon within reference documentation, especially for a large project like Android.

这篇关于谷歌地图查看"而在Android的例子&QUOT语境的问题;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆