Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8317931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:46:40+00:00 2026-06-08T21:46:40+00:00

I’m getting very weird NullPointerException when trying to get current zoom level from my

  • 0

I’m getting very weird NullPointerException when trying to get current zoom level from my MapView. The problem is that this occurs not every time and happens somewhere inside getZoomLevel() function. Investigating the source code of this function shows that this is just a getter function and NullPointerException should not potentially happen here. The mapView itself is not null at the time it happens and calls to other MapView interfaces (such as getProjection() work fine).

Here is a brief background of my code structure:

I have map view and ItemizedOverlay with certain amount of items. When I have new data – I need to coalesce items which are close to each other. One of the params to coalesce() function is current zoom level which in theory I should be able to get from my MapView.

I tried to place call to coalesce() inside uiThread but I still get NullPointerException sometimes.

I managed to workaround this issue by keeping track of last known zoomLevel within my custom map view and returning it when getZoomLevel fails:

public final int getCurrentZoomLevel() 
{
    try 
    {
        return this.getZoomLevel();
    } catch (Exception ex) 
    {
        ex.printStackTrace();
        return lastZoomLevel;
    }
}

But still, I’m curious why it happens.
It happens on different devices and different Android versions.

Here is stack trace:

07-18 11:31:22.435: W/System.err(8054): java.lang.NullPointerException
07-18 11:31:22.435: W/System.err(8054):     at com.google.android.maps.MapView.getZoomLevel(MapView.java:1094)
07-18 11:31:22.435: W/System.err(8054):     at com.inrix.lib.view.CustomMapView.getCurrentZoomLevel(CustomMapView.java:195)
07-18 11:31:22.435: W/System.err(8054):     at com.inrix.lib.mapitems.incidents.IncidentMapItemOverlay.performCoalesceInternal(IncidentMapItemOverlay.java:109)
07-18 11:31:22.435: W/System.err(8054):     at com.inrix.lib.mapitems.MapItemsOverlay$4.run(MapItemsOverlay.java:448)
07-18 11:31:22.435: W/System.err(8054):     at java.lang.Thread.run(Thread.java:1096)
07-18 11:31:22.435: W/System.err(8054):     at com.inrix.lib.mapitems.MapItemsOverlay.recoalesce(MapItemsOverlay.java:450)
07-18 11:31:22.442: W/System.err(8054):     at com.inrix.lib.mapitems.MapItemsOverlay$2.run(MapItemsOverlay.java:281)
07-18 11:31:22.442: W/System.err(8054):     at android.os.Handler.handleCallback(Handler.java:587)
07-18 11:31:22.442: W/System.err(8054):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-18 11:31:22.442: W/System.err(8054):     at android.os.Looper.loop(Looper.java:123)
07-18 11:31:22.442: W/System.err(8054):     at android.app.ActivityThread.main(ActivityThread.java:4627)
07-18 11:31:22.442: W/System.err(8054):     at java.lang.reflect.Method.invokeNative(Native Method)
07-18 11:31:22.442: W/System.err(8054):     at java.lang.reflect.Method.invoke(Method.java:521)
07-18 11:31:22.442: W/System.err(8054):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-18 11:31:22.442: W/System.err(8054):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-18 11:31:22.442: W/System.err(8054):     at dalvik.system.NativeStart.main(Native Method)

Call to coalesce looks like:

protected void performCoalesceInternal(IOnCoalesceCompleteListener callback) 
{
    if (callback != null) 
    {
        callback.onCoalesceComplete(coalescer.coalesce(
                mapItemsController.getRawItemsCollection(), 
                MapItemType.Incident,  
                mapView.getCurrentZoomLevel(), 
                mapView.getProjection()));
    }
}

Please note that I have NullPointerException only on getZoomLevel() call. mapView.getProjection() works fine.

Activity creation/initialization stage:

public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ........

    this.setContentView(R.layout.content_inrixmap_activity);

    // Initialize map.
    this.mapView = (CustomMapView) findViewById(R.id.map_view);

    ........

    // Create overlays.
    this.currentLocationOverlay = new CurrentLocationOverlay(this.mapView);
    this.trafficTileOverlay = new TrafficTileOverlay(new TrafficTileManager(this, this.trafficTileHandler));
    this.cameraOverlay = new CameraMapItemOverlay(this, this.mapView, this);
    this.incidentsOverlay = new IncidentMapItemOverlay(this, this.mapView, this);

    // Add overlays to map.
    this.mapView.addOverlay(this.trafficTileOverlay);
    this.mapView.addOverlay(this.currentLocationOverlay);
    this.mapView.addOverlay(this.cameraOverlay);
    this.mapView.addOverlay(this.incidentsOverlay);
    this.mapView.preLoad();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T21:46:42+00:00Added an answer on June 8, 2026 at 9:46 pm

    Apparently the problem is a bit specific to my code. Apparently, android caches instance of a mapView to be processed by a callback. And when my activity gets recreated, callback uses old instance which is valid, but unitialized.

    Solved by cancelling all active network requests when mapView gets recreated

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.