Monday, 10 October 2016

XML : Android View subclass java.lang.RuntimeException: view tag isn't correct on view:null

I'm getting an error when I try to use my subclassed RelativeLayout when I also have databinding. My goal is to have a subclassed view that also has databinding as part of it. If what I'm doing is wrong, is there another way I can do this? When I run the app, everything is fine by the preview gives off this error when trying to render.

  java.lang.RuntimeException: view tag isn't correct on view:null    

My XML layout file:

  <?xml version="1.0" encoding="utf-8"?>  <layout xmlns:android="http://schemas.android.com/apk/res/android">      <RelativeLayout          android:id="@+id/view"          android:layout_width="fill_parent"          android:layout_height="fill_parent">            <TextView              android:id="@+id/tv_ttl_first_name"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_centerInParent="true"              android:text="First Name:"              android:layout_alignParentLeft="true"              android:layout_alignParentTop="true"/>            <TextView              android:id="@+id/tv_first_name"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_centerInParent="true"              android:text="First Name"              android:layout_marginLeft="30dp"              android:layout_alignBaseline="@id/tv_ttl_first_name"              android:layout_toRightOf="@id/tv_ttl_first_name"              />      </RelativeLayout>  </layout>    

And I have a subclass of Relative layout which uses that XML:

  public class ContainerSingleBabyInfo extends RelativeLayout {      private static final String TAG = ContainerSingleBabyInfo.class.getSimpleName();      protected ContainerSingleBabyInformationBinding binding;        //region Overrides      public ContainerSingleBabyInfo(Context context, AttributeSet attrs) {          super(context, attrs);          this.init(context);      }        public ContainerSingleBabyInfo(Context context, AttributeSet attrs, int defStyle) {          super(context, attrs, defStyle);          this.init(context);      }        public ContainerSingleBabyInfo(Context context) {          super(context);          this.init(context);      }        private void init(Context context) {          LayoutInflater inflater =  LayoutInflater.from(context);          binding = DataBindingUtil.inflate(inflater, R.layout.container_single_baby_information, this, true);      }  }    

And here of the snippet of my using my class:

  <com.foo.bar.Views.InfoContainers.ContainerSingleBabyInfo      android:id="@+id/vw_single_baby_info"      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:layout_below="@id/vw_icons"      android:layout_above="@+id/vw_fresh_btn_container"      android:visibility="visible"      layout="@layout/container_single_baby_information"/>    

No comments:

Post a Comment