Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on marker click #218

Closed
mobilecipl opened this issue Oct 26, 2015 · 11 comments
Closed

Crash on marker click #218

mobilecipl opened this issue Oct 26, 2015 · 11 comments

Comments

@mobilecipl
Copy link

When i try to render my kml file it gets crash on one of the markers click ,when i track the issue ,i find the issue NullPointerException in one of the in library.

@black-snow
Copy link

You should post the full stack trace and the important bits of your code.

@gitkobold
Copy link

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at java.io.StringReader.(StringReader.java:47)
at android.text.HtmlToSpannedConverter.convert(Html.java:442)
at android.text.Html.fromHtml(Html.java:136)
at android.text.Html.fromHtml(Html.java:99)
at com.google.maps.android.kml.KmlRenderer$1.getInfoContents(KmlRenderer.java:573)
at com.google.android.gms.maps.GoogleMap$13.zzg(Unknown Source)
at com.google.android.gms.maps.internal.zzd$zza.onTransact(Unknown Source)
at android.os.Binder.transact(Binder.java:380)
at com.google.android.gms.maps.internal.f$a$a.b(:com.google.android.gms.alldynamite:112)
at maps.ei.h.a(Unknown Source)
at maps.ei.h.a(Unknown Source)
at maps.dg.c.b(Unknown Source)
at maps.dg.d.c(Unknown Source)
at maps.ei.s.g(Unknown Source)
at maps.ei.t.b(Unknown Source)
at maps.dg.c.a(Unknown Source)
at maps.dz.w.a(Unknown Source)
at maps.dz.ae.a(Unknown Source)
at maps.dz.ad.a(Unknown Source)
at maps.dz.an.d(Unknown Source)
at maps.dz.q.onSingleTapConfirmed(Unknown Source)
at maps.dc.f.onSingleTapConfirmed(Unknown Source)
at maps.dc.g$a.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6873)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

@black-snow
Copy link

After clicking a Marker? How do you initialize your markers? Do you set the title/subtitle? Please post the corresponding bit of code.

@gitkobold
Copy link

@black-snow
Copy link

Looks like your markers don't have any text set; see

My knowledge of kml is little. Looking at

private void setMarkerInfoWindow(KmlStyle style, Marker marker,
- do you have any of these props set (in your kml - for each placemark)? (text, name or description) Seems like it's mandatory to have one of these set at least.

/edit: Threw a short glimpse on https://developers.google.com/kml/documentation/kmlreference#feature - didn't see that any of these are actually mandatory. Might be a bug in the maps-utils. @markmcd You'll probably know better.

@gitkobold
Copy link

Hi,

This is the affected part of the kml:

<Style id="start"
<IconStyle>
<Icon>
<href>start.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="finish">
<IconStyle>
<Icon>
<href>
finish.png
</href>
</Icon>
</IconStyle>
</Style>
<Style id="order">
<IconStyle>
<Icon>
<href>order.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark>
<styleUrl>#start</styleUrl>
<name>Kiindulás</name>
<description/>
<Point>
<coordinates>19.0210083333,46.441605</coordinates>
</Point>
</Placemark>
etc...

I don't know how kml could be correct but I don't think if something is missing from the kml it should cause a crash.
But if the crash can be avoided please suggest what I have to modify (app modification would be prefered). Thanks a lot

@black-snow
Copy link

I guess I saw a KML validator on the interwebs - you could give it a try.
It could also be that infoWindowText is null ... You can always wrap the part in a try-catch-block and silently discard the NPE. If the info windows pop up empty it's an issue with arg0 i. e. the Marker that's being created.

@gitkobold
Copy link

Which part can be wrapped? The code (https://github.com/googlemaps/android-maps-utils/blob/master/demo/src/com/google/maps/android/utils/demo/KmlDemoActivity.java) doesn't have custom infowindow part.
I think something is wrong in the demo code if it's crashing. Even if the kml doesn't have all fields.

@Vandalko
Copy link
Contributor

Vandalko commented Apr 1, 2016

@gitkobold based on your KML snippet I've created test file and it seem to cause no crash on latest library version

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="start">
    <IconStyle>
      <Icon>
        <href>start.png</href>
      </Icon>
    </IconStyle>
  </Style>
  <Style id="finish">
    <IconStyle>
      <Icon>
        <href>
          finish.png
        </href>
      </Icon>
    </IconStyle>
  </Style>
  <Style id="order">
    <IconStyle>
      <Icon>
        <href>order.png</href>
      </Icon>
    </IconStyle>
  </Style>
  <Placemark>
    <styleUrl>#start</styleUrl>
    <name>Kiindulás</name>
    <description/>
    <Point>
      <coordinates>19.0210083333,46.441605</coordinates>
    </Point>
  </Placemark>
  </Document>
</kml>

Based on your stacktrace, crash can happen only if Marker has no title.
I don't know how the rest of your KML document looks like but the quickest solution would be to call map.setInfoWindowAdapter(null) after you've added the KML layer (kmlLayer.addLayerToMap() call)

So this would use build-in window adapter (or you may create your own).

@gitkobold
Copy link

Thanks a lot Vandalko, it's working!

@Libby713
Copy link
Contributor

Libby713 commented Dec 5, 2016

Fixed in 0d92651

@Libby713 Libby713 closed this as completed Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants