Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException when using RelativeLayout as custom InfoWindow
    primarykey
    data
    text
    <p>I'm trying to use a <code>RelativeLayout</code> as custom <code>InfoWindow</code> for my markers, but a I get a <code>NullPointerException</code> every time <code>showInfoWindow</code> is called (via tapping on a <code>Marker</code> or programmatically). I'm using Google Maps Android API v2.</p> <p><strong>Exception:</strong></p> <pre class="lang-java prettyprint-override"><code>FATAL EXCEPTION: main java.lang.NullPointerException at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:465) at android.view.View.measure(View.java:15172) at maps.a.y.i(Unknown Source) at maps.a.y.a(Unknown Source) at maps.a.w.a(Unknown Source) at maps.a.bd.a(Unknown Source) at maps.y.bw.b(Unknown Source) at maps.y.bw.a(Unknown Source) at maps.a.dh.a(Unknown Source) at maps.a.n.c(Unknown Source) at maps.a.dw.a(Unknown Source) at maps.a.bd.c(Unknown Source) at maps.a.dq.onSingleTapConfirmed(Unknown Source) at maps.e.v.onSingleTapConfirmed(Unknown Source) at maps.e.j.handleMessage(Unknown Source) ... </code></pre> <p><strong>My code:</strong></p> <p>*custom_infowindow.xml*</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dip" &gt; &lt;ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:paddingLeft="10dip" android:paddingRight="10dip" android:paddingTop="5dip" android:src="@drawable/icon" /&gt; &lt;TextView android:id="@+id/title" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toLeftOf="@id/icon" android:ellipsize="end" android:paddingLeft="10dip" android:paddingRight="10dip" android:singleLine="true" /&gt; &lt;TextView android:id="@+id/snippet" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/title" android:layout_toLeftOf="@id/icon" android:ellipsize="end" android:paddingBottom="10dip" android:paddingLeft="10dip" android:paddingRight="10dip" android:singleLine="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><em>CustomInfoWindowAdapter.java</em></p> <pre class="lang-java prettyprint-override"><code>public class CustomInfoWindowAdapter implements InfoWindowAdapter { private View layout; private LayoutInflater inflater; public CustomInfoWindowAdapter(Context context) { inflater = LayoutInflater.from(context); } @Override public View getInfoContents(Marker marker) { return null; } @Override public View getInfoWindow(Marker marker) { ViewHolder holder; if (layout == null) { layout = inflater.inflate(R.layout.custom_infowindow, null); holder = new ViewHolder(); holder.title = (TextView) layout.findViewById(R.id.title); holder.snippet = (TextView) layout.findViewById(R.id.snippet); layout.setTag(holder); } else { holder = (ViewHolder) layout.getTag(); } holder.title.setText(marker.getTitle()); holder.snippet.setText(marker.getSnippet()); return layout; } static class ViewHolder { TextView title; TextView snippet; } } </code></pre> <p>Funny thing is that if I use <code>LinearLayout</code> instead it works just fine, but I'd rather use only one <code>ViewGroup</code> if possible. And of course I would like to know what happens with that <code>onMeasure</code> throwing a <code>NullPointerException</code>.</p> <p>EDIT: Also, wrapping the <code>RelativeLayout</code> inside a <code>FrameLayout</code> or a <code>LinearLayout</code> will work. Wrapping it inside another <code>RelativeLayout</code> won't, of course.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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