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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:38:26+00:00 2026-05-27T14:38:26+00:00

Making a simple map app, plan on adding buttons to mark specific locations But

  • 0

Making a simple map app, plan on adding buttons to mark specific locations

But right now it crashes when I zoom.

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;


import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class Main extends MapActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable);

    GeoPoint point = new GeoPoint(19240000,-99120000);
    OverlayItem overlayitem = new OverlayItem(point, "Hola, Mundo!", "I'm in Mexico City!");

    itemizedoverlay.addOverlay(overlayitem);
    mapOverlays.add(itemizedoverlay);
    }



@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
   }

When I touch the built in zoom, it forces the application to close.

Any help would be great.

edit: Stacktrace

12-16 05:40:04.012: D/dalvikvm(2473): GC_FOR_MALLOC freed 4578 objects / 277208 bytes in 49ms
12-16 05:40:04.151: I/MapActivity(2473): Handling network change notification:CONNECTED
12-16 05:40:04.151: E/MapActivity(2473): Couldn't get connection factory client
12-16 05:40:04.271: D/dalvikvm(2473): GC_FOR_MALLOC freed 3049 objects / 271640 bytes in 49ms
12-16 05:40:08.491: D/AndroidRuntime(2473): Shutting down VM
12-16 05:40:08.491: W/dalvikvm(2473): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-16 05:40:08.551: E/AndroidRuntime(2473): FATAL EXCEPTION: main
12-16 05:40:08.551: E/AndroidRuntime(2473): java.lang.NullPointerException
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:743)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.app.AlertDialog$Builder.<init>(AlertDialog.java:273)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.b00517566.la.MyItemizedOverlay.onTap(MyItemizedOverlay.java:46)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.google.android.maps.ItemizedOverlay.onTap(ItemizedOverlay.java:453)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.google.android.maps.OverlayBundle.onTap(OverlayBundle.java:83)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.google.android.maps.MapView$1.onSingleTapUp(MapView.java:347)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.google.android.maps.GestureDetector.onTouchEvent(GestureDetector.java:533)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.google.android.maps.MapView.onTouchEvent(MapView.java:647)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.View.dispatchTouchEvent(View.java:3766)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)

12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.os.Looper.loop(Looper.java:123)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at java.lang.reflect.Method.invokeNative(Native Method)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at java.lang.reflect.Method.invoke(Method.java:521)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-16 05:40:08.551: E/AndroidRuntime(2473):     at dalvik.system.NativeStart.main(Native Method)
12-16 05:40:11.023: I/Process(2473): Sending signal. PID: 2473 SIG: 9

EDIT

    package com.bleh.la;

    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.OverlayItem;

     public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {


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


public MyItemizedOverlay(Drawable defaultMarker) {
      super(boundCenterBottom(defaultMarker));
    }

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

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

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

public MyItemizedOverlay(Drawable defaultMarker, Context context) {
      super(defaultMarker);
      mContext = context;
    }

@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;
}
    }
  • 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-05-27T14:38:26+00:00Added an answer on May 27, 2026 at 2:38 pm

    I think , this line give you null pointer exception

     AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    

    Here mContext is null

    because of In your Main.java you are calling,

    MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable);
    

    instead of call

      MyItemizedOverlay itemizedoverlay = new MyItemizedOverlay(drawable,this);
    

    And your constructor should be like,

    public MyItemizedOverlay(Drawable drawable,Context cxt){
            super(boundCenter(drawable));
             this.mContext = cxt;
        }
    

    EDIT: Look at the Sample Project

    Using Google Maps in Android

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

Sidebar

Related Questions

I have created a simple map app that shows the local garage sales in
now.. I was making a program.. but I want to make the program connected
Im making a simple wallpaper changer. It works when changing the wallpaper but i
Im making a simple alternative to the default linux system monitor. Im looking to
I am making a simple game in order to learn a new language. I
I'm making a simple 2 player game in XNA and started looking into saving
I'm making a simple scheduler with C# in .Net. All it does is execute
If I'm making a simple grid based game, for example, I might have a
I'm making a simple 2D game for the iPhone. It's based on CrashLanding. so
I'm making a simple form to create polls, therefore I want the possibility to

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.