gpt4 book ai didi

android - SeekBar DataBinding 表达式上的资源 NotFoundException

转载 作者:行者123 更新时间:2023-11-29 17:01:42 27 4
gpt4 key购买 nike

我正在尝试为 SeekBar onProgressChanged 调用一个使用 lambda 表达式的方法,但我遇到了这个异常:

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)

这是布局:

<?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>

和 fragment 代码:

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;
}

}

主持人:

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()));
}
}

我的代码有什么问题?

最佳答案

异常不是由SeekBar引起的绑定(bind)问题是android:text="@{filter.minRating}"我也看不到你在哪里设置 filter

由于您没有发布您的 br.com.app.model.Filter 代码,我猜 minRating 是一个整数。因此,绑定(bind)需要一个字符串资源,在您的情况下为 id 0。

因此只需将minRating 的类型更改为String

关于android - SeekBar DataBinding 表达式上的资源 NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42519935/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com