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 9210165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:00:22+00:00 2026-06-18T01:00:22+00:00

I am making a map application for android which allows the user to place

  • 0

I am making a map application for android which allows the user to place their own points of interest. I wanted to set custom pushpin icons for each type of point placed. When I try to get my custom ItemizedOverlay at run time, I get a NullPointerException.

Add a point to the map:

public void addPointToMap(PointOfInterest pointOfInterest) {

    OurItemizedOverlay itemizedOverlay = getOverlayForPointOfInterest(pointOfInterest); <--- NullPointer here
    //Add item to collection in OurItemized Overlay
    itemizedOverlay.addOverlay(pointOfInterest);
    mapOverlays.clear();
    mapOverlays.add(myLocationOverlay);
    mapOverlays.add(itemizedOverlay);
    mapView.invalidate();
}

Get Overlay:

private OurItemizedOverlay getOverlayForPointOfInterest(PointOfInterest pointOfInterest) {

       String type = pointOfInterest.getType().toLowerCase();

       if(type.equals("monument")) {
           return monumentOverlay;
       }
       else if(type.equals("building")) {
           return buildingOverlay;
       }
       else if(type.equals("atm")) {
           return atmOverlay;
       }
       else if(type.equals("attraction")) {
           return attractionOverlay;
       }
       else if(type.equals("pub")) {
           return pubOverlay;
       }
       else if(type.equals("restaurant")) {
           return restaurantOverlay;
       }
       else if(type.equals("shop")) {
           return shopOverlay;
       }
       else if(type.equals("bridge")) {
           return bridgeOverlay;
       }
       else if(type.equals("station")) {
           return stationOverlay;
       }
       else if(type.equals("cafe")) {
           return cafeOverlay;
       }
       else if(type.equals("hotel")) {
           return hotelOverlay;
       }
       else {
           return defaultOverlay; 
       }
}

Set up Drawables and Overlays:

/**
 * Set the overlay objects up
 */
private void setItemizedOverlays() {

    //SET OVERLAY Items
    monumentOverlay = new OurItemizedOverlay(monumentIcon, this);
    buildingOverlay = new OurItemizedOverlay(buildingIcon, this);
    shopOverlay = new OurItemizedOverlay(shopIcon, this);
    attractionOverlay = new OurItemizedOverlay(attractionIcon, this);
    bridgeOverlay = new OurItemizedOverlay(bridgeIcon, this);
    stationOverlay = new OurItemizedOverlay(stationIcon, this);
    pubOverlay = new OurItemizedOverlay(pubIcon, this);
    restaurantOverlay = new OurItemizedOverlay(restaurantIcon, this);
    cafeOverlay = new OurItemizedOverlay(cafeIcon, this);
    atmOverlay = new OurItemizedOverlay(atmIcon, this);
    hotelOverlay = new OurItemizedOverlay(hotelIcon, this);


}

/**
 * Set the icons for each Drawable object
 */
private void setDrawableIcons() {

    defaultIcon = this.getResources().getDrawable(R.drawable.downarrow);
    monumentIcon = this.getResources().getDrawable(R.drawable.monument);
    shopIcon = this.getResources().getDrawable(R.drawable.shop);
    attractionIcon = this.getResources().getDrawable(R.drawable.attraction);
    buildingIcon = this.getResources().getDrawable(R.drawable.building);
    bridgeIcon = this.getResources().getDrawable(R.drawable.bridge);
    stationIcon = this.getResources().getDrawable(R.drawable.station);
    pubIcon = this.getResources().getDrawable(R.drawable.pub);
    restaurantIcon = this.getResources().getDrawable(R.drawable.restaurant);
    cafeIcon = this.getResources().getDrawable(R.drawable.cafe);
    atmIcon = this.getResources().getDrawable(R.drawable.atm);
    hotelIcon = this.getResources().getDrawable(R.drawable.hotel);


}

StackTrace:

01-29 18:17:11.875: E/AndroidRuntime(12380): FATAL EXCEPTION: main
01-29 18:17:11.875: E/AndroidRuntime(12380): java.lang.NullPointerException
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.example.mapproject.MainActivity.addPointToMap(MainActivity.java:140)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.example.mapproject.MainActivity.onPointsOfInterestDownloaded(MainActivity.java:227)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.example.mapproject.DownloadPointsOfInterest.onPostExecute(DownloadPointsOfInterest.java:67)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.example.mapproject.DownloadPointsOfInterest.onPostExecute(DownloadPointsOfInterest.java:1)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.os.AsyncTask.finish(AsyncTask.java:602)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.os.AsyncTask.access$600(AsyncTask.java:156)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.os.Looper.loop(Looper.java:137)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at android.app.ActivityThread.main(ActivityThread.java:4441)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at java.lang.reflect.Method.invokeNative(Native Method)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at java.lang.reflect.Method.invoke(Method.java:511)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
01-29 18:17:11.875: E/AndroidRuntime(12380):    at dalvik.system.NativeStart.main(Native Method)

Any pointers would be appreciated !

  • 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-18T01:00:24+00:00Added an answer on June 18, 2026 at 1:00 am

    Most likely error- you went into your default case, I don’t see an initialization for defaultOverlay in setItemizedOverlays. But this is a good case for a debugger, figure out which branch it went into in getOverlayForPointOfInterest and see why its getting null.

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

Sidebar

Related Questions

I'm making a map application. I'd like the user to see X in my
Friends i am making an application in which i am using Map Activity. Now
Making a simple application, so when the user logs out of Windows, it of
I will be making a mobile application in Android. My application is like Google
I am making Map application and I have already able to call web service
I am making an application based on Google map implementation. Everything is working fine
One part of the application I am making requires google map. I want the
I'm making a C# inventory application. However, I want there to be a map
I am making an app in which i have to show Map in my
I'm making an application where I need to map sockets to some object. 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.