Android Question

Resources NotFoundException on SeekBar DataBinding expression

I'm trying to invoke a method using lambda expression for SeekBar

onProgressChanged
, but I'm getting this exception:

android.content.res.Resources$NotFoundException: String resource ID #0x0
at android.content.res.Resources.getText(Resources.java:336)
at android.widget.TextView.setText(TextView.java:4465)
at br.com.caradviser.app.databinding.FragmentFilterBinding.executeBindings(FragmentFilterBinding.java:476)
at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:355)
at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:172)
at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:142)
at android.view.View.dispatchAttachedToWindow(View.java:14714)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2962)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2969)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1599)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1321)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6708)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:894)
at android.view.Choreographer.doCallbacks(Choreographer.java:696)
at android.view.Choreographer.doFrame(Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:880)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:5728)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)


Here is the layout:

<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:grid="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="br.com.app.fragments.FilterFragment">

<data>

<variable
name="filter"
type="br.com.app.model.Filter"/>

<variable
name="presenter"
type="br.com.app.contract.FilterContract.Presenter" />
</data>

<RelativeLayout
android:id="@+id/content_filter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_filter">


<!--
Some widgets omitted for brevity
-->

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/separator_2"
android:text="Nota Mínima" />

<SeekBar
android:id="@+id/bar_min_rating"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView3"
android:max="5"
android:progress="@={filter.minRating}"
android:onProgressChanged="@{(seekBar, progress, fromUser) -> presenter.minRatingChanged(seekBar)}" />

<TextView
android:id="@+id/text_rating_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/bar_min_rating"
android:text="@{filter.minRating}"
android:translationX="12dp" />

</RelativeLayout>
</layout>


And the Fragment code:

public class FilterFragment extends Fragment
implements FilterContract.View {

private FragmentFilterBinding mViewDataBinding;
private FilterContract.Presenter mPresenter;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_filter, container, false);

mViewDataBinding = FragmentFilterBinding.bind(view);

Filter model = new Filter();
mViewDataBinding.setFilter(model);

return view;
}

}


Presenter:

public class FilterPresenter implements FilterContract.Presenter {

private final FilterContract.View mView;

public FilterPresenter(FilterContract.View mView) {
this.mView = mView;

mView.setPresenter(this);
}

public void start() {

}

@Override
public void maxDistanceChanged(int position) {

}

@Override
public void minRatingChanged(SeekBar seekBar) {
Log.d("minRatingChanged", String.valueOf(seekBar.getProgress()));
}
}


What is wrong with my code?

Answer Source

Exception is not caused by SeekBar binding problem is android:text="@{filter.minRating}" Also i can't see where you are setting filter.

As you did not post the code of your br.com.app.model.Filter i guess minRating is a integer. So binding expects a string resource with , in your case id 0 .

So just change the type of minRating to String.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download