Android : Why do I get java.lang.UnsupportedOperationException?

on Sunday, March 22, 2015


can you explain to me why I get "FATAL EXCEPTION: java.lang.UnsupportedOperationException" on refreshing my content? In normal case, the function should download the data and creates a recycler / card for every line...



public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mSwipeRefreshLayout.setRefreshing(false);
}
}, 2500);

new Thread(new Runnable(){
public void run(){

if(!isNetworkAvailable()){
Toast.makeText(getApplicationContext(), getResources().getString(R.string.nointernet), Toast.LENGTH_LONG).show();
return;
}

String str=getOnline("http://ni141767_1.vweb12.nitrado.net/vp.php");
String lines[] = str.split("\\<.*?\\>");
for (int i = 0; i < lines.length; i++) {
String content[] = lines[i].split("_");

String fach = content[5];
String lehrer = content[6];

Data dataToAdd = new Data(fach,lehrer);
mData.add(dataToAdd);
mAdapter.addItem(i, dataToAdd);

content = null;
}

}
}).start();
}


Data.java:



public class Data {
public String text;
public String lehrer;
public Data(String text, String lehrer) {
this.text = text;
this.lehrer = lehrer;
}
}


CustomRecyclerAdapter.java:



import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Collections;
import java.util.List;

public class CustomRecyclerAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {

private List<Data> mData = Collections.emptyList();

public CustomRecyclerAdapter() {
// Pass context or other static stuff that will be needed.
}

public void updateList(List<Data> data) {
mData = data;
notifyDataSetChanged();
}
@Override
public int getItemCount() {
return mData.size();
}

@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View itemView = inflater.inflate(R.layout.card, viewGroup, false);
return new RecyclerViewHolder(itemView);
}

@Override
public void onBindViewHolder(RecyclerViewHolder viewHolder, int position) {
viewHolder.fach.setText(mData.get(position).text);
viewHolder.lehrer.setText(mData.get(position).lehrer);
}
public void addItem(int position, Data data) {
mData.add(position, data);
notifyItemInserted(position);
}

public void removeItem(int position) {
mData.remove(position);
notifyItemRemoved(position);
}

}


RecyclerViewHolder.java:



import android.support.v7.widget.RecyclerView;


import android.view.View; import android.widget.TextView;



public class RecyclerViewHolder extends RecyclerView.ViewHolder {

public TextView fach;
public TextView lehrer;

public RecyclerViewHolder(View itemView) {
super(itemView);
fach = (TextView) itemView.findViewById(R.id.fach);
lehrer = (TextView) itemView.findViewById(R.id.lehrer);
}
}

0 comments:

Post a Comment