Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android.support.v7.widget.RecyclerView$ViewHolder.shouldIgnore()';关于空对象引用_Java_Android - Fatal编程技术网

Java android.support.v7.widget.RecyclerView$ViewHolder.shouldIgnore()';关于空对象引用

Java android.support.v7.widget.RecyclerView$ViewHolder.shouldIgnore()';关于空对象引用,java,android,Java,Android,嗨,当我想将一些新数据设置到我的RecyclerView时,所有这些都会发生firsTime正常但当我想刷新我的RecyclerView(代码中的else部分)时,会发生此错误。我知道此错误适用于RecyclerView.Animation,请参阅以下代码: RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) {

嗨,当我想将一些新数据设置到我的
RecyclerView
时,所有这些都会发生
firsTime
正常但当我想刷新我的
RecyclerView
(代码中的else部分)时,会发生此错误。我知道此错误适用于
RecyclerView.Animation
,请参阅以下代码:

 RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
  if (animator instanceof SimpleItemAnimator) {
       ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
  }
我将此代码放入我的片段
onCreateView
,很抱歉,我的问题没有得到解决

谁能告诉我出了什么问题吗?谢谢

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_distance_report_lists, container, false);

    RecyclerView recyclerView = new RecyclerView(view.getContext());
    //((SimpleItemAnimator) recyclerView.getItemAnimator()).setSupportsChangeAnimations(false);

    RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
   if (animator instanceof SimpleItemAnimator) {
        ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
    }
    if (TextUtils.isEmpty(distance)) {
        recyclerView.setAdapter(new RecyclerViewAdapterDistance(jCars, cntx));
        recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));

    } else {

        recyclerView.setAdapter(new RecyclerViewAdapterDistance(cntx, fromDate, fromTime, toDate, toTime, distance, jCars));
        recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
    }
    return recyclerView;
}

而不是以这种方式RecyclerView RecyclerView=new RecyclerView(view.getContext());请在“碎片距离报告列表”布局中添加RecylerView尝试以这种方式访问RecyclerView rv=view.findviewbyid(R.id.recyclerviewid)

请检查这个例子

fragment_blank.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".BlankFragment">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

希望这将解决您的问题干杯

Sey布局参数到recyclerview

   RecyclerView.LayoutParams params = new RecyclerView.LayoutParams
                                               (ViewGroup.LayoutParams.MATCH_PARENT,
                                                ViewGroup.LayoutParams.WRAP_CONTENT);
            recyclerView.setLayoutParams(params);
有关详细说明,请访问此链接

尝试在活动中使用findViewById()绑定回收器视图

RecyclerView mRecyclerView= view.findViewById(R.id.recycler_view)// recycler_view is the id of RecyclerView in XML file.

哦,朋友们,我发现了我的错误,那是我把数据发送给回收站的错误,所有这些都是为了帮助我 这对我来说是真的

  RecyclerViewAdapterDistance_Map recyclerViewAdapterDistanceMap = new RecyclerViewAdapterDistance_Map(jCars, cntx,false);
        mrecyclerView.setAdapter(recyclerViewAdapterDistanceMap);    
        RecyclerViewAdapterDistance_Map recyclerViewAdapterDistanceMap2 = new RecyclerViewAdapterDistance_Map(cntx, fromDate, fromTime, toDate, toTime, distance, jCars,false);
        mrecyclerView.setAdapter(recyclerViewAdapterDistanceMap2);
    mrecyclerView.setLayoutManager(new LinearLayoutManager(cntx));
然后是碎片

 FragmentActivity fragmentRow = getActivity();
                    FragmentManager fragmentManager = fragmentRow.getSupportFragmentManager();
                    Fragment listFragment = fragmentManager.findFragmentById(R.id.carsList);
                    DistanceReportLists distanceReportLists = new DistanceReportLists().newInstance(jcar, cntx, edtFromDate.getText().toString(), tvFromTime.getText().toString(), edtToDate.getText().toString(), tvToTime.getText().toString(), String.valueOf(distance));
                    FragmentTransaction transaction = fragmentRow.getSupportFragmentManager().beginTransaction();
                    if (listFragment != null) {
                        transaction.remove(listFragment);
                    }
                    transaction.replace(R.id.fragment_list, distanceReportLists);
                    transaction.commit();

视图=充气机。充气(R.layout.fragment\u distance\u report\u list,container,false)=LayoutFlater.from(cntx).充气(R.layout.fragment_distance_report_List,mrecyclServiceAdapterDistance,false);//您在哪里分配此值?@Ankita sorry“=LayoutInflater.from(cntx).inflate(R.layout.fragment_distance_report_list,mrecyclServiceAdapterDistance,false);”在我的副本中是错误的。请检查下面贴出的答案。谢谢。我已经读过了,这是duc,这是dont answer给我的:(在返回声明中,你需要返回view而不是recycle视图,谢谢。请原谅我。你能告诉我一个例子吗?
 FragmentActivity fragmentRow = getActivity();
                    FragmentManager fragmentManager = fragmentRow.getSupportFragmentManager();
                    Fragment listFragment = fragmentManager.findFragmentById(R.id.carsList);
                    DistanceReportLists distanceReportLists = new DistanceReportLists().newInstance(jcar, cntx, edtFromDate.getText().toString(), tvFromTime.getText().toString(), edtToDate.getText().toString(), tvToTime.getText().toString(), String.valueOf(distance));
                    FragmentTransaction transaction = fragmentRow.getSupportFragmentManager().beginTransaction();
                    if (listFragment != null) {
                        transaction.remove(listFragment);
                    }
                    transaction.replace(R.id.fragment_list, distanceReportLists);
                    transaction.commit();