Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps hashmap with LatLng
    text
    copied!<p>I have created one simple class which called MapMarker and it is the following: <br/></p> <pre><code>public class MapMarker { private long id; private String resName; public MapMarker(){} public MapMarker(long id, String resName){ this.id = id; this.resName = resName; } public long getId(){ return id; } public String getResName(){ return resName; } } </code></pre> <p>while i am adding the markers in the google map i also create a HashMap in order when a infowindow is clicked i can start an activity with some parameters. The code i am using is the following for adding the markers and initilize the hashmap<br/></p> <pre><code>private HashMap&lt;LatLng, MapMarker&gt; mapMarkersData = new HashMap&lt;LatLng, MapMarker&gt;(); markerCoords = new LatLng(lat, lng); mapMarkersData.put(markerCoords, new MapMarker(markerId, markerRes)); map.addMarker(new MarkerOptions().position(markerCoords).title(title).snippet("Click to see more info!")); </code></pre> <p>when i try to get the value from the hashmap i get a nullpointerexception. The code i am using is the following. <br/></p> <pre><code>line 360: markerId = mapMarkersData.get(marker.getPosition()).getId(); markerResName = mapMarkersData.get(marker.getPosition()).getResName(); </code></pre> <p>What is going wrong?</p> <p>Edit:<br/> the logcat is the following: <br/></p> <pre><code>02-23 20:37:55.780: E/AndroidRuntime(4853): FATAL EXCEPTION: main 02-23 20:37:55.780: E/AndroidRuntime(4853): java.lang.NullPointerException 02-23 20:37:55.780: E/AndroidRuntime(4853): at .MapActivity.onInfoWindowClick (MapActivity.java:360) 02-23 20:37:55.780: E/AndroidRuntime(4853): at .GoogleMap$8.h(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at com.google.android.gms.internal.u$a.onTransact(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at android.os.Binder.transact(Binder.java:279) 02-23 20:37:55.780: E/AndroidRuntime(4853): at com.google.android.gms.maps.internal.IOnInfoWindowClickListener$Stub$Proxy.onInfoWindowClick(IOnInfoWindowClickListener.java:82) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.y.bw.a(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.a.y.f(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.a.y.a(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.a.bd.c(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.a.dq.onSingleTapConfirmed(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.e.v.onSingleTapConfirmed(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at maps.e.j.handleMessage(Unknown Source) 02-23 20:37:55.780: E/AndroidRuntime(4853): at android.os.Handler.dispatchMessage(Handler.java:99) 02-23 20:37:55.780: E/AndroidRuntime(4853): at android.os.Looper.loop(Looper.java:130) 02-23 20:37:55.780: E/AndroidRuntime(4853): at android.app.ActivityThread.main(ActivityThread.java:3691) 02-23 20:37:55.780: E/AndroidRuntime(4853): at java.lang.reflect.Method.invokeNative(Native Method) 02-23 20:37:55.780: E/AndroidRuntime(4853): at java.lang.reflect.Method.invoke(Method.java:507) 02-23 20:37:55.780: E/AndroidRuntime(4853): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 02-23 20:37:55.780: E/AndroidRuntime(4853): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670) 02-23 20:37:55.780: E/AndroidRuntime(4853): at dalvik.system.NativeStart.main(Native Method) </code></pre> <p>Sorry one last edit has been made.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload