NullPointerException when using RelativeLayout as custom InfoWindow

前端 未结 3 2029
自闭症患者
自闭症患者 2020-12-23 21:51

I\'m trying to use a RelativeLayout as custom InfoWindow for my markers, but a I get a NullPointerException every time showInfoW

相关标签:
3条回答
  • 2020-12-23 22:32

    I experienced this issue even when I didn't have a RelativeLayout in my xml. It turns out that my class backing the XML inherited from RelativeLayout, even though it was a LinearLayout.

    It didn't cause a bug for several different devices, but when I tried on my S3 it crashed.

    Anyways, just either remove or wrap the RelativeLayout or set a layout height/width first.

    0 讨论(0)
  • 2020-12-23 22:42

    I had this problem and was able to fix it by adding

    view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth,desiredHeight));
    

    to the view before returning it from InfoWindowAdapter.getInfoWindow

    0 讨论(0)
  • 2020-12-23 22:45

    Just found out that in android version < 4.4 this generates a nullpointer exception. Changing the layout with a Linear one will solve the problem.

    0 讨论(0)
提交回复
热议问题