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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:30:06+00:00 2026-06-02T07:30:06+00:00

I am working on a piece of an application attempting to show multiple different

  • 0

I am working on a piece of an application attempting to show multiple different overlays onto a mapView at the same time. The reason being the different overlays need to be different colors. I had a working map that allowed for scrolling and zoom, but after adding multiple overlays the map now gives a null pointer exception whenever I try to scroll, and the zoom buttons have disappeared.

Here is my Map Activity:

package com.example.UVAMapsProject;

import java.util.ArrayList;
import java.util.List;

import com.example.UVAMapsProject.R;
import com.example.UVAMapsProject.R.drawable;
import com.example.UVAMapsProject.R.id;
import com.example.UVAMapsProject.R.layout;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class MapsActivity extends MapActivity {
    /** Called when the activity is first created. */
    Context mContext;
    MapView mapView;
    private MapController mapController;
    List<Overlay> mapOverlays;
    Drawable drawableStandard;
    Drawable drawableComplete;
    Drawable drawableNext;
    HelloItemizedOverlay itemizedOverlayStandard;
    HelloItemizedOverlay itemizedOverlayNext;
    HelloItemizedOverlay itemizedOverlayComplete;

    ArrayList<GeoPoint> overlayPoints = new ArrayList<GeoPoint>();
    ArrayList<Destination> tourListTemp = SplashActivity.tourApp1.getTheTour().getTourList();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maps);

        //get current center, create map at center
        int lat = (int)NavigatorActivity.currentLocation.getLatitude();
        int lon = (int)NavigatorActivity.currentLocation.getLongitude();
        GeoPoint point = new GeoPoint((int)(lat*1e6), (int)(lon*1e6) );
        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(false);
        mapController = mapView.getController();
        mapController.setZoom(10);
        mapController.setCenter(point);

        // Initializes three different images and itemized overlays for each type of overlay
        drawableStandard = this.getResources().getDrawable(R.drawable.androidmarker);
        itemizedOverlayStandard = new HelloItemizedOverlay(drawableStandard, mapView);
        drawableNext = this.getResources().getDrawable(R.drawable.androidmarkernext);
        itemizedOverlayNext = new HelloItemizedOverlay(drawableNext, mapView);
        drawableComplete = this.getResources().getDrawable(R.drawable.androidmarkercomplete);
        itemizedOverlayComplete = new HelloItemizedOverlay(drawableStandard, mapView);

        // get points of Destinations & make overlays
        addOverlayPoints();

        mapController.zoomToSpan(itemizedOverlayStandard.getLatSpanE6(), itemizedOverlayStandard.getLonSpanE6());

        final MyLocationOverlay myPosition = new MyLocationOverlay(this,mapView);
        mapOverlays = mapView.getOverlays();  
        mapOverlays.add(myPosition);
        mapOverlays.add(itemizedOverlayStandard);
        mapOverlays.add(itemizedOverlayNext);
        mapOverlays.add(itemizedOverlayComplete);
        myPosition.enableMyLocation();

    }


    public void addOverlayPoints(){
        for (Destination d: tourListTemp) {
        GeoPoint temp = new GeoPoint((int)(tourListTemp.get(tourListTemp.indexOf(d)).getLatitude()*1e6),
                (int)(tourListTemp.get(tourListTemp.indexOf(d)).getLongitude()*1e6));
        overlayPoints.add(temp);
        OverlayItem overlayitem = new OverlayItem(temp, d.getName(), d.getInfo());
        itemizedOverlayStandard.addOverlay(overlayitem);
        }
        itemizedOverlayNext.addOverlay(itemizedOverlayStandard.removeOverlay(tourListTemp.get(0)));
    }

Here is my Overlay Class:

package com.example.UVAMapsProject;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

public class HelloItemizedOverlay extends ItemizedOverlay {

    private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
    Context mContext;
    MapView mapView;

    public HelloItemizedOverlay(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
        // TODO Auto-generated constructor stub
    }

    public HelloItemizedOverlay(Drawable defaultMarker, MapView mv) {
          super(boundCenterBottom(defaultMarker));
          mContext = mv.getContext();
    }

    @Override
    protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
      AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
      dialog.setTitle(item.getTitle());
      dialog.setMessage(item.getSnippet());
      dialog.show();
      return true;
    }

    @Override
    protected OverlayItem createItem(int i) {
      return mOverlays.get(i);
    }

    public int getOverlayIndex(Destination d){
        int out = SplashActivity.tourApp1.getTheTour().getTourList().indexOf(SplashActivity.tourApp1.getNextDestination());
        return out;
    }

    public OverlayItem removeOverlay(Destination d) {
        int index = getOverlayIndex(d);
        OverlayItem temp = mOverlays.get(index);
        mOverlays.remove(index);
        return temp;
    }

    public void addOverlay(OverlayItem overlay) {
        mOverlays.add(overlay);
        populate();
    }

    @Override
    public int size() {
      return mOverlays.size();
    }

}

Here is the error I receive when clicking the map:

04-18 15:56:46.980: E/AndroidRuntime(3262): FATAL EXCEPTION: main
04-18 15:56:46.980: E/AndroidRuntime(3262): java.lang.NullPointerException
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:643)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.View.dispatchTouchEvent(View.java:3766)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.os.Looper.loop(Looper.java:123)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at java.lang.reflect.Method.invokeNative(Native Method)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at java.lang.reflect.Method.invoke(Method.java:521)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-18 15:56:46.980: E/AndroidRuntime(3262):     at dalvik.system.NativeStart.main(Native Method)
  • 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-02T07:30:08+00:00Added an answer on June 2, 2026 at 7:30 am

    In the HelloItemizedOverlay constructor you need to call populate()

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

Sidebar

Related Questions

I'm working on a piece of code for an iPhone application that fetches a
I've been working on a piece of software where I need to generate a
I have a working piece of code in the application delegate that contains a
One of the components I need for an application I am working on is
Thanks in advance for your time :-) I am working on an MVC3 application
I'm working on a piece of a web application in ASP.Net MVC where the
I am working on an application where users will be evaluating a piece of
The Rails application I'm working on, has two central pieces: users and groups. A
I'm working on a piece of code that I inherited and am trying to
I am working on a piece of code which uses regular expressions in c.

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.