0
   if (Geocoder.isPresent()) {
            geocoder = new Geocoder(MapActivity.this.getactivity,Locale.getDefault());

This is inside doitbackground of asynctask. It is inner class of mapactivity.

But i cant do this. The error is:

mapactivity not enclosing class

When i make only this.

it says

in geocoder can not be applied context

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

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

those did not work because i am in inner class. I cant use constructor to initialize context?

Also putting inner class name as first parameter did not work.

Error:

 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)
Community
  • 1
  • 1
  • If you extend Application, then you can have a static reference to it. A static instance of the application can thus be used as a valid context when ui is not needed. Alternatively you could simply pass a context as an argument to your inner class. – cYrixmorten Dec 10 '15 at 18:33

1 Answers1

0

Declare a context variable near the top of your activity and get the context:

 Context context = YourActivity.getApplicationContext();

Then use your context variable for the geocoder:

  if (Geocoder.isPresent()) {
        geocoder = new Geocoder(context, Locale.getDefault());
joshgoldeneagle
  • 4,616
  • 2
  • 23
  • 30