Error when trying to access Overlay text

Put problem concerning MapActivities, MapViews, Overlays and GPS in this forum.

Error when trying to access Overlay text

Postby hwrdprkns » Wed Mar 24, 2010 6:38 pm

Hi guys,

I'm getting a NullPointerException when I am trying to access the overlay text in on my AVD. It displays the overlay fine, but when I click on it, the program starts force closing.

Here is the onTap method where I tell it what to do when I click on the overlay:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.         protected boolean onTap(int index)
  4.  
  5.         {
  6.  
  7.                 OverlayItem item = mOverlays.get(index);
  8.  
  9.                 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  10.  
  11.                 dialog.setTitle(item.getTitle());
  12.  
  13.                 dialog.setMessage(item.getSnippet());
  14.  
  15.                 dialog.show();
  16.  
  17.                 return true;
  18.  
  19.         }
  20.  
  21.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Here is where I first call it in my main activity:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  //Add the overlay to the specified GeoPoint
  2.  
  3.            GeoPoint point = new GeoPoint ((int)(lat*1E6), (int) (lng*1E6));
  4.  
  5.            OverlayItem overlayitem = new OverlayItem(point,"Hello world","Ohai, this is where I am");
  6.  
  7.            itemizedoverlay.addOverlay(overlayitem);
  8.  
  9.            mapOverlays.add(itemizedoverlay);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Any ideas would be greatly appreciated! Thanks again!

Here are the pastebins for the full code:

Main Acivity

ItimizedOverlay class
The more you learn, the less you know.
hwrdprkns
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Nov 25, 2009 8:14 am

Top

Postby prodeveloper » Sun Apr 11, 2010 1:57 am

Hey, I've been having the same problem, so if anyone has found a solution, please tell. Thanks.
prodeveloper
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 11, 2010 1:47 am

Had same problem

Postby ethan.close » Mon Apr 19, 2010 6:33 am

Here's a link that will show you how to fix it. The tutorial currently has errors. :cry:

http://osdir.com/ml/Android-Beginners/2 ... 00222.html

Basically,

In HelloGoogleMaps.java, add "this" in the itemized overlay declaration:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable,this);
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


In HelloItemizedOverlay.java add the boundCinterBottom method on default marker:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public HelloItemizedOverlay(Drawable defaultMarker, Context context)
  2.  
  3. {
  4.  
  5.    super(boundCenterBottom(defaultMarker));
  6.  
  7.    mContext = context;
  8.  
  9. }
  10.  
  11.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


~ Ethan
ethan.close
Freshman
Freshman
 
Posts: 5
Joined: Fri Mar 19, 2010 12:53 am
Location: San Francisco

Postby prodeveloper » Wed Apr 21, 2010 1:56 am

It worked! Thank you so much!
prodeveloper
Freshman
Freshman
 
Posts: 6
Joined: Sun Apr 11, 2010 1:47 am

Top

Return to Map Problems

Who is online

Users browsing this forum: No registered users and 3 guests