Unable to call Snapshotter class from HttpServlet class

Unable to call Snapshotter class from HttpServlet class

Questions : Unable to call Snapshotter class from HttpServlet class


I’m trying to build a rest endpoint where in4codes_java user will pass style.json url and zxy in4codes_java values. According to the input I have to in4codes_java create a snapshot of that map tile. If I use in4codes_java the mapbox’s Snapshotter in an activity I’m in4codes_java able to create snapshot. With HttpServlet in4codes_java I’m also able to get style and zxy But when in4codes_java I try to create snapshot from a class that in4codes_java extend HttpServlet I can’t pass in4codes_java HttpServlet’s context to snapshotter class.

Can Anyone please let me know what can I in4codes_java pass to snapshotter class in this case to in4codes_java take a map snapshot?

Here is a part of my httpservlet class’s in4codes_java code

public final class TileRequest extends HttpServlet { @Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException { Log.e("FileJson", " extend HttpServlet get called"); File file = this.takeSnapshot(); assert file != null; String url = NavDrawerMainActivity.getConnectionUtility().getUrl() + Constants.RequestConstants.REQUEST_GET_TILE_STR + file.getName(); JSONObject jsonObject = new JSONObject(); try { jsonObject.put("name", file.getName()); jsonObject.put("url", url); } catch (JSONException e) { e.printStackTrace(); } try { response.getOutputStream().write(jsonObject.toString().getBytes()); } catch (IOException e) { e.printStackTrace(); } } } 

In the takeSnapshot(); method this the in4codes_java mapbox snapshotter class which take Context in4codes_java and as constructor agrument

MapSnapshotter mapSnapshotter = new MapSnapshotter(NavDrawerMainActivity.getmContext(), snapShotOptions); 

I have tried TileRequest.this in new in4codes_java MapSnapshotter it does not accept that then in4codes_java I created a static context method in main in4codes_java activity and call it in new MapSnapshotter in4codes_java but it does not work with that too. It in4codes_java throws exception

java.lang.IllegalStateException: ThreadUtils in4codes_java isn’t correctly initialised

Please let me know what to pass as context in4codes_java or how can I pass context to the in4codes_java snapshotter?

Total Answers 1

Answers 1 : of Unable to call Snapshotter class from HttpServlet class

You need to double check that the mapbox in4codes_java is initialized correctly.

Mapbox.getInstance(getApplicationContext(), BuildConfig.MapboxAccessToken); 

In my case, I will instantiate it in the in4codes_java class that inherits Application:

public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Mapbox.getInstance(getApplicationContext(), BuildConfig.MapboxAccessToken); } }