Skip to Content

Object Header Data Binding

Hi SAP Team,

I am trying to use databinding in conjunction with with the Object Header component, but it just partially works for me.
I can bind data to headline/subheadline/footnote etc., but as soon as I try to bind data to the status TextViews I added to the Object Header, I get the following Nullpointer Exception:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.apsolut.inbox.demo, PID: 8383
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.apsolut.inbox.demo/com.apsolut.inbox.ui.PRItemDetailActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTag(java.lang.Object)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTag(java.lang.Object)' on a null object reference
        at com.apsolut.inbox.databinding.ItemDetailObjectHeaderBindingImpl.<init>(ItemDetailObjectHeaderBindingImpl.java:34)
        at com.apsolut.inbox.databinding.ItemDetailObjectHeaderBindingImpl.<init>(ItemDetailObjectHeaderBindingImpl.java:25)
        at com.apsolut.inbox.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:44)
        at androidx.databinding.MergedDataBinderMapper.getDataBinder(MergedDataBinderMapper.java:74)
        at androidx.databinding.DataBindingUtil.bind(DataBindingUtil.java:199)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1250)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1266)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1266)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:1266)
        at androidx.databinding.ViewDataBinding.mapBindings(ViewDataBinding.java:717)
        at com.apsolut.inbox.databinding.ItemPrDetailBindingImpl.<init>(ItemPrDetailBindingImpl.java:39)
        at com.apsolut.inbox.DataBinderMapperImpl.getDataBinder(DataBinderMapperImpl.java:50)
        at androidx.databinding.MergedDataBinderMapper.getDataBinder(MergedDataBinderMapper.java:74)
        at androidx.databinding.DataBindingUtil.bind(DataBindingUtil.java:199)
        at androidx.databinding.DataBindingUtil.bindToAddedViews(DataBindingUtil.java:327)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:306)
        at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
        at com.apsolut.inbox.ui.PRItemDetailActivity.onCreate(PRItemDetailActivity.java:28)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6669) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 


XML Object Header (This is an include file which works fine as long as I do not try to bind data to the Textviews):

<layout>
    <data>
        <variable
            name="bodyText"
            type="String" />
        <variable
            name="footnoteText"
            type="String" />
        <variable
            name="headlineText"
            type="String" />
        <variable
            name="subheadlineText"
            type="String" />
        <variable
            name="statusText1"
            type="String" />
        <variable
            name="statusText2"
            type="String" />
        <variable
            name="descriptionText"
            type="String" />
    </data>
    <com.sap.cloud.mobile.fiori.object.ObjectHeader xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/detail_object_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:body="@{bodyText ?? ``}"
        app:dynamicStatusWidth="true"
        app:footnote="@{footnoteText ?? ``}"
        app:headline="@{headlineText ?? ``}"
        app:description="@{descriptionText ?? ``}"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:preserveDescriptionSpacing="false"
        app:preserveDetailImageSpacing="false"
        app:preserveIconImageContainer="false"
        app:preserveIconStackSpacing="false"
        app:subheadline="@{subheadlineText ?? ``}">

        <TextView
            android:id="@+id/object_header_status"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:text="@{statusText1 ?? ``}"
            android:textColor="@color/white"
            app:layout_header_group="STATUS" />

        <TextView
            android:id="@+id/object_header_prio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center_vertical"
            android:paddingTop="5dp"
            android:text="@{statusText2 ?? ``}"
            android:textColor="@color/white"
            app:layout_header_group="STATUS" />
    </com.sap.cloud.mobile.fiori.object.ObjectHeader>
</layout>

Is this a bug within the component or do I have to apply the data through the Object Header instead of directly referencing the TextViews ?

Setting the data programmatically like this works for example:

objectHeader.setStatus("Status 1", 0);
objectHeader.setStatus("Status 2", 1);

Hope you can help me out.

Regards

Eduard

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Aug 04, 2020 at 06:27 PM

    Hi Eduard,

    The XML looks fine. The error message is complaining about setTag, which I cannot find in ObjectHeader or AbstractEntityCell. Can you double check where the `setTag` call comes from?

    Thanks,

    Hui Cao

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.