0

I'm working on an android application that registers consumptions of materials for production in warehouses. I am using Androids UI Navigation architecture component to handle the navigation within the app. In every Fragment I am using the same onCreateView function:

override fun onCreateView(
    inflater: LayoutInflater, container: ViewGroup?,
    savedInstanceState: Bundle?
): View? {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_layout, container, false)

    return inflater.inflate(R.layout.fragment_layout, container, false)
}

where fragment_layout is the resource id of the current Fragments layout.

My problem now is, that in one single Fragment the call to DataBindingUtil.inflate is causing an InvocationTargetException.

I already commented out the complete layout to check if some errors are present in the layout file. After that, I commented out all the logic for the views inside the fragment. This led to the same exception over and over again.

The last test I did was to change the line code inside onCreateView from

binding = DataBindingUtil.inflate(inflater, R.layout.consumption_fragment, container, false)

return binding.root

to:

return inflater.inflate(R.layout.fragment_layout, container, false)

After that, all the problems were gone. But this solution is not suitable for me because I need to use the data bindings.

This is the data section of the layout file in question

<data>
    <import type="Field" />
    <import type="androidx.lifecycle.LiveData" />
    <import type="java.util.List" />
        <variable
            name="parcelNo"
            type="Field&lt;String>" />
        <variable
            name="piece"
            type="Field&lt;String>" />

        <variable
            name="parcels"
            type="LiveData&lt;List&lt;Consumption>>" />

        <variable
            name="parcel"
            type="LiveData&lt;Parcel>" />
    </data>

The stack trace that is shown in the logcat does not provide very much information about where the error occurs.

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  • I'm facing same issue on my project .Please help me to solve this issue – Mohit Lakhanpal Feb 07 '20 at 04:25
  • @Mohit Lakhanpal in my case it turned out, that there was a bigger cause around the runtime exception. It was caused by a missing dependency in my Koin module which I used for DI. After adding the dependency the fragment had no problems running. I hope this helps you with the Problem. – Fabian Fahrenholz Mar 10 '20 at 17:23
  • I solved this issue. This issue was in my style file while I set a wrong attribute on the XML file – Mohit Lakhanpal Mar 11 '20 at 05:00

0 Answers0