Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.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 notifydatasetchanged在应用程序关闭后不工作?_Java_Android - Fatal编程技术网

Java notifydatasetchanged在应用程序关闭后不工作?

Java notifydatasetchanged在应用程序关闭后不工作?,java,android,Java,Android,我的代码如下。我有几个类,当有人想要更新时,它不起作用。有什么问题吗? 我检查了很多,应用程序关闭=arrayAdapter.notifyDataSetChanged() 公共类CardArrayAdapter扩展了ArrayAdapter{ 公共CardArrayAdapter(上下文、int资源、列表对象){ 超级(上下文、资源、对象); } @非空 @凌驾 公共视图getView(int位置、视图转换视图、视图组父视图){ 卡片=获取项目(位置); convertView=LayoutIn

我的代码如下。我有几个类,当有人想要更新时,它不起作用。有什么问题吗? 我检查了很多,应用程序关闭=arrayAdapter.notifyDataSetChanged()

公共类CardArrayAdapter扩展了ArrayAdapter{
公共CardArrayAdapter(上下文、int资源、列表对象){
超级(上下文、资源、对象);
}
@非空
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
卡片=获取项目(位置);
convertView=LayoutInflater.from(getContext()).flate(R.layout.item,父项,false);
TextView TextView=convertView.findViewById(R.id.ItemTextView);
ImageView ImageView=convertView.findViewById(R.id.ItemImageView);
textView.setText(card.name);
Glide.with(getContext()).load(card.photoURL).into(imageView);
返回视图;
}
}
主类

ArrayList<Card> list;
CardArrayAdapter arrayAdapter;
public void loadsCards(){
        list=new ArrayList<Card>();
         String name = dataSnapshot.child("name").getValue().toString();
                                    String photoURL = dataSnapshot.child("photo").getValue().toString();
                                    String uid = dataSnapshot.getKey();
                                    Card card = new Card(uid,photoURL,name);
                                    Toast.makeText(getActivity(), "sonuc:"+card.name, Toast.LENGTH_LONG).show();
                                   list.add(card);
                       arrayAdapter.notifyDataSetChanged(); //closes here
                                  }
ArrayList列表;
CardarayAdapter arrayAdapter;
公共空间荷载等级(){
列表=新的ArrayList();
字符串名称=dataSnapshot.child(“名称”).getValue().toString();
字符串photoURL=dataSnapshot.child(“photo”).getValue().toString();
字符串uid=dataSnapshot.getKey();
卡片=新卡(uid、photoURL、名称);
Toast.makeText(getActivity(),“sonuc:+card.name,Toast.LENGTH\u LONG.show();
列表。添加(卡片);
arrayAdapter.notifyDataSetChanged();//在此处关闭
}

我猜您正在尝试使用
RecyclerView
并用
arrayAdapter
填充它。您缺少指示recycler视图使用适配器的语句

尝试添加此项并检查其是否有效

recyclerView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();
如果您正在使用任何其他视图,如
ListView
,则必须将适配器设置为该视图

listView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();
如果不使用任何视图,则无法填充数据。有关ArrayAdapter的更多信息,请查看本文: ,我解决了这个问题。
list=newarraylist()
//添加代码

arrayAdapter=new-cardarayadapter(this.getContext(),list.size(),list)

Stacktrace。我解决了这个问题。列表=新的ArrayList()//添加代码arrayAdapter=新的CardArrayAdapter(this.getContext(),list.size(),list);//谢谢你帮你解决这个问题。
listView.setAdapter(arrayAdapter);
arrayAdapter.notifyDataSetChanged();