首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >构造函数Geocoder.Geocoder(上下文)不适用

构造函数Geocoder.Geocoder(上下文)不适用
EN

Stack Overflow用户
提问于 2015-12-10 17:18:11
回答 1查看 345关注 0票数 0
代码语言:javascript
复制
   if (Geocoder.isPresent()) {
            geocoder = new Geocoder(MapActivity.this.getactivity,Locale.getDefault());

这是在doitbackground of asynctask内部。它是地图活性的inner class

但我不能这么做。错误是:

代码语言:javascript
复制
mapactivity not enclosing class

当我做这个的时候。

上面写着

代码语言:javascript
复制
in geocoder can not be applied context

"The constructor Geocoder(Context, Locale) is undefined"?

Error: The constructor Geocoder (Context, Locale) is undefined

这些都没用,因为我在内科学课上。我不能使用构造函数来初始化上下文吗?

同时,将内部类名作为第一个参数也不起作用。

错误:

代码语言:javascript
复制
 no suitable constructor found for Geocoder(RetrieveFeedTask,Locale)
constructor Geocoder.Geocoder(Context) is not applicable
(actual and formal argument lists differ in length)
constructor Geocoder.Geocoder(Context,Locale) is not applicable
(actual argument RetrieveFeedTask cannot be converted to Context by method invocation conversion)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-10 18:41:54

在活动顶部附近声明一个上下文变量,并获取上下文:

代码语言:javascript
复制
 Context context = YourActivity.getApplicationContext();

然后,将上下文变量用于Geo编码器:

代码语言:javascript
复制
  if (Geocoder.isPresent()) {
        geocoder = new Geocoder(context, Locale.getDefault());
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34207942

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档