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

  • Home
  • SEARCH
  • 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 8878633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:45:32+00:00 2026-06-14T19:45:32+00:00

Hey people i am new to android here am working with a map oriented

  • 0

Hey people i am new to android here am working with a map oriented project now i got a problem while i touch on the overlay item it shows null-pointer exception in log-cat i cannot understand what does it mean.Here i have two classes MyPlacemapActivity and AddItemizedOverlay somebody please help me to fix this and here is my class codes

AddItemizedOverlay.java

public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {

       private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();

       private Context context;
       String reference;
       private String username;

       String p_u_name;
       public AddItemizedOverlay(Drawable defaultMarker) {
            super(boundCenterBottom(defaultMarker));
       }

       public AddItemizedOverlay(Drawable defaultMarker, Context context) {
            this(defaultMarker);
            this.context = context;
       }

       public AddItemizedOverlay(Drawable defaultMarker, Context context,String StringData) {
                   this(defaultMarker);
                   this.context = context;
       this.username=StringData;
       System.out.println("AdditemizedOverlay:got username:"+username +StringData);
              }


       @Override
       public boolean onTouchEvent(MotionEvent event, MapView mapView)
       {   
               if (event.getAction() == 1) {
               GeoPoint geopoint = mapView.getProjection().fromPixels(
                   (int) event.getX(),
                   (int) event.getY());
           }
           return false;
       } 

       @Override
       protected OverlayItem createItem(int i) {
          return mapOverlays.get(i);
       }
       @Override
       public int size() {
          return mapOverlays.size();
       }

      @Override
       protected boolean onTap(int index) {
         OverlayItem item = mapOverlays.get(index);
         AlertDialog.Builder dialog = new AlertDialog.Builder(this.context);
         reference = item.getSnippet();
         username =  item.getTitle();
         dialog.setTitle("");
         dialog.setMessage("Do you want ot park here ?");
         System.out.println("Inside Additemized:"+reference+username);
         dialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {


                SharedPreferences prefs = context.getSharedPreferences("myprefs", 0);
                SharedPreferences.Editor editor =prefs.edit();
                editor.putString("KEY_REFERENCE", reference);
                editor.putString("KEY_USERNAME", username);
                editor.commit();                

                Intent intent = new Intent(context, SinglePlaceActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(intent);
            }
         })
            .setNegativeButton("No",new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
//                  MainActivity.this.finish();
                }
            });
         dialog.show();
         return true;
       }

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

       public void populateNow(){
           this.populate();
       }

    }

MyPlacemapActivity.java

public class MyPlacemapActivity extends MapActivity {
    // Nearest places
    PlacesList nearPlaces;

    // Map view
    MapView mapView;

    // Map overlay items
    List<Overlay> mapOverlays;

    AddItemizedOverlay itemizedOverlay;
    MyItemizedOverlay myitemizedoverlay;
    FindItemizedOverlay finditemizedoverlay;

    GeoPoint geoPoint;
    // Map controllers
    MapController mc;

    Drawable defaultMarker,drawable;

    double latitude;
    double longitude;
    OverlayItem overlayitem;

    String p_u_name;
    String type,keyword;

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

        SharedPreferences prefs = getSharedPreferences("myprefs", 0);
        p_u_name = prefs.getString("KEY_USERNAME", "");

        Intent i = getIntent();

        // Users current geo location
        String user_latitude = i.getStringExtra("user_latitude");
        String user_longitude = i.getStringExtra("user_longitude");
        type = i.getExtras().getString("KEY_TYPES");
        keyword =i.getExtras().getString("KEY_KEYWORD");

        System.out.println("sarath"+user_latitude + user_longitude + type);

        // Nearplaces list
        nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

        mapView = (MapView) findViewById(R.id.mapView);
        mapView.setBuiltInZoomControls(true);

        mapOverlays = mapView.getOverlays();

        // Geopoint to place on map
        geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),(int) (Double.parseDouble(user_longitude) * 1E6));

        // Drawable marker icon
        Drawable drawable_user = this.getResources().getDrawable(R.drawable.mark_red);

        myitemizedoverlay = new MyItemizedOverlay(drawable_user, this);

        // Map overlay item
        overlayitem = new OverlayItem(geoPoint, "Your Location","That is you!");

        myitemizedoverlay.addOverlay(overlayitem);

        mapOverlays.add(myitemizedoverlay);
        myitemizedoverlay.populateNow();

        System.out.println("keyword:"+keyword+"type:"+type);
//----------------------------------------------------------------------------------------------------------        
        // Drawable marker icon
        if(type.equalsIgnoreCase("gas_station")&&keyword.equalsIgnoreCase("gas_station")){
             drawable= this.getResources().getDrawable(R.drawable.mark_gasstation);
             finditemizedoverlay = new FindItemizedOverlay(drawable);

        mc = mapView.getController();

        // These values are used to get map boundary area
        // The area where you can see all the markers on screen
        int minLat = Integer.MAX_VALUE;
        int minLong = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int maxLong = Integer.MIN_VALUE;

        // check for null in case it is null
        if (nearPlaces.results != null) {


            // loop through all the places
            for (Place mplace : nearPlaces.results) {

                latitude = mplace.geometry.location.lat; // latitude
                longitude = mplace.geometry.location.lng; // longitude

                // Geopoint to place on map
                geoPoint = new GeoPoint((int) (latitude * 1E6),
                        (int) (longitude * 1E6));

                // Map overlay item
                overlayitem = new OverlayItem(geoPoint,p_u_name,mplace.reference);

                finditemizedoverlay.addOverlay(overlayitem);

                // calculating map boundary area
                minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
                minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
                maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
                maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
            }
            mapOverlays.add(finditemizedoverlay);

            // showing all overlay items
            finditemizedoverlay.populateNow();
        }


        // Adjusting the zoom level so that you can see all the markers on map
        mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

        // Showing the center of the map
        mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
        mapView.postInvalidate();
        }

        else if(type.equalsIgnoreCase("shopping_mall")&&keyword.equalsIgnoreCase("shopping_mall")){
            drawable= this.getResources().getDrawable(R.drawable.mark_shopping);
             finditemizedoverlay = new FindItemizedOverlay(drawable);

        mc = mapView.getController();

        // These values are used to get map boundary area
        // The area where you can see all the markers on screen
        int minLat = Integer.MAX_VALUE;
        int minLong = Integer.MAX_VALUE;
        int maxLat = Integer.MIN_VALUE;
        int maxLong = Integer.MIN_VALUE;

        // check for null in case it is null
        if (nearPlaces.results != null) {


            // loop through all the places
            for (Place mplace : nearPlaces.results) {

                latitude = mplace.geometry.location.lat; // latitude
                longitude = mplace.geometry.location.lng; // longitude

                // Geopoint to place on map
                geoPoint = new GeoPoint((int) (latitude * 1E6),
                        (int) (longitude * 1E6));

                // Map overlay item
                overlayitem = new OverlayItem(geoPoint,p_u_name,mplace.reference);

                finditemizedoverlay.addOverlay(overlayitem);

                // calculating map boundary area
                minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
                minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
                maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
                maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
            }
            mapOverlays.add(finditemizedoverlay);

            // showing all overlay items
            finditemizedoverlay.populateNow();
        }


        // Adjusting the zoom level so that you can see all the markers on map
        mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

        // Showing the center of the map
        mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
        mapView.postInvalidate();
        }

    else if(type.equalsIgnoreCase("restaurant")&&keyword.equalsIgnoreCase("restaurant")){
        drawable= this.getResources().getDrawable(R.drawable.mark_restaurant_blue);
         finditemizedoverlay = new FindItemizedOverlay(drawable);

    mc = mapView.getController();

    // These values are used to get map boundary area
    // The area where you can see all the markers on screen
    int minLat = Integer.MAX_VALUE;
    int minLong = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int maxLong = Integer.MIN_VALUE;

    // check for null in case it is null
    if (nearPlaces.results != null) {


        // loop through all the places
        for (Place mplace : nearPlaces.results) {

            latitude = mplace.geometry.location.lat; // latitude
            longitude = mplace.geometry.location.lng; // longitude

            // Geopoint to place on map
            geoPoint = new GeoPoint((int) (latitude * 1E6),
                    (int) (longitude * 1E6));

            // Map overlay item
            overlayitem = new OverlayItem(geoPoint,p_u_name,mplace.reference);

            finditemizedoverlay.addOverlay(overlayitem);

            // calculating map boundary area
            minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
            minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
            maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
            maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
        }
        mapOverlays.add(finditemizedoverlay);

        // showing all overlay items
        finditemizedoverlay.populateNow();
    }


    // Adjusting the zoom level so that you can see all the markers on map
    mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

    // Showing the center of the map
    mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
    mapView.postInvalidate();
    }

    else if(type.equalsIgnoreCase("parking")&&keyword.equalsIgnoreCase("garage parking")){
        drawable= this.getResources().getDrawable(R.drawable.mark_blue);
         itemizedOverlay = new AddItemizedOverlay(drawable);

    mc = mapView.getController();

    // These values are used to get map boundary area
    // The area where you can see all the markers on screen
    int minLat = Integer.MAX_VALUE;
    int minLong = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int maxLong = Integer.MIN_VALUE;

    // check for null in case it is null
    if (nearPlaces.results != null) {


        // loop through all the places
        for (Place mplace : nearPlaces.results) {

            latitude = mplace.geometry.location.lat; // latitude
            longitude = mplace.geometry.location.lng; // longitude

            // Geopoint to place on map
            geoPoint = new GeoPoint((int) (latitude * 1E6),
                    (int) (longitude * 1E6));

            // Map overlay item
            overlayitem = new OverlayItem(geoPoint,p_u_name,mplace.reference);

            System.out.println("inside mymap:"+mplace.reference+p_u_name);

            itemizedOverlay.addOverlay(overlayitem);

            // calculating map boundary area
            minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
            minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
            maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
            maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
        }
        mapOverlays.add(itemizedOverlay);

        // showing all overlay items
        itemizedOverlay.populateNow();
    }


    // Adjusting the zoom level so that you can see all the markers on map
    mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

    // Showing the center of the map
    mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
    mapView.postInvalidate();
    }
    else if(type.equalsIgnoreCase("parking")&&keyword.equalsIgnoreCase("street parking")){
        drawable= this.getResources().getDrawable(R.drawable.mark_blue);
         itemizedOverlay = new AddItemizedOverlay(drawable);

    mc = mapView.getController();

    // These values are used to get map boundary area
    // The area where you can see all the markers on screen
    int minLat = Integer.MAX_VALUE;
    int minLong = Integer.MAX_VALUE;
    int maxLat = Integer.MIN_VALUE;
    int maxLong = Integer.MIN_VALUE;

    // check for null in case it is null
    if (nearPlaces.results != null) {


        // loop through all the places
        for (Place mplace : nearPlaces.results) {

            latitude = mplace.geometry.location.lat; // latitude
            longitude = mplace.geometry.location.lng; // longitude

            // Geopoint to place on map
            geoPoint = new GeoPoint((int) (latitude * 1E6),
                    (int) (longitude * 1E6));

            // Map overlay item
            overlayitem = new OverlayItem(geoPoint,p_u_name,mplace.reference);

            System.out.println("inside mymap:"+mplace.reference +p_u_name);

            itemizedOverlay.addOverlay(overlayitem);

            // calculating map boundary area
            minLat  = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
            minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
            maxLat  = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
            maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
        }
        mapOverlays.add(itemizedOverlay);

        // showing all overlay items
        itemizedOverlay.populateNow();
    }


    // Adjusting the zoom level so that you can see all the markers on map
    mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

    // Showing the center of the map
    mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
    mapView.postInvalidate();
    }
    else
    {
         AlertDialog.Builder builder = new AlertDialog.Builder(MyPlacemapActivity.this);
           builder.setTitle("Connection Error.");
           builder.setMessage("Try again?.")  
                  .setCancelable(false)
                  .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface dialog, int id) {
                          Intent u = new Intent(getApplicationContext(),Find_TabActivity.class);
                          startActivity(u);
                        dialog.dismiss();
                      }
                  });                     
           AlertDialog alert = builder.create();
           alert.show();    
    }
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

}
  • 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-14T19:45:33+00:00Added an answer on June 14, 2026 at 7:45 pm

    The problem is with the line:

    finditemizedoverlay = new FindItemizedOverlay(drawable);
    

    You are initilizing a ItemizedOverlay without passing the contex required for the onTap() method to create the AletDialo.

    You should replace it by:

    finditemizedoverlay = new FindItemizedOverlay(drawable, this);
    

    Note: it helps if you put the logcat in your question.

    Regards.

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

Sidebar

Related Questions

Elegant Solution Hey People. I'm currently working on a Project and I am thinking
hey people I'm new at jquery and i have been trying to figure this
Hey guys, got a problem with a question. Question : Write a declaration for
Hey people, i have a the following map* which is giving me lots of
Hey people I've been searching over the internet for the following problem without success...
Hey, I'm trying to write a program that will accept new tasks from people,
Emulator --- Device Hey people. I'm not very experienced in Android development, so I
Hey, I'm working on an iPhone app but I've heard from some people that
hey people.i would like to know how to develop applications for android. i know
Hey people out there.. Im working on making a application with tabview where in

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.