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<String>" />
<variable
name="piece"
type="Field<String>" />
<variable
name="parcels"
type="LiveData<List<Consumption>>" />
<variable
name="parcel"
type="LiveData<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)