Hi I try to fill an Arraylist in a Fragment with data from a Sqlite table (the table already has data) and it shows me the error of the title in the catch.
Class HomeFragment
public class InicioFragment extends Fragment {
public RecyclerView recyclerView;
public RecyclerView.Adapter adapter;
public RecyclerView.LayoutManager layoutManager;
public SearchView searchView;
public Context context;
public ArrayList<InicioItem> arrayList;
UtilidadesSQLite inicio;
public List<UtilidadesSQLite > listCreditos;
private conexion con;
SQLiteDatabase bd;
String id;
public InicioFragment() { }
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_inicio, container, false);
id=getArguments().getString("id");
inicio= new UtilidadesSQLite ();
recyclerView = (RecyclerView) rootView.findViewById(R.id.rclvInicio);
recyclerView.setHasFixedSize(true);
searchView = (SearchView) rootView.findViewById(R.id.searchInicio);
this.context = this.getContext();
arrayList = new ArrayList<InicioItem>();
listCreditos=new ArrayList<Inicio>();
arrayList=GetArrayListInicioItem();
adapter = new InicioRecyclerAdapter(context, arrayList);
recyclerView.setAdapter(adapter);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return rootView;
}
public ArrayList<InicioItem> GetArrayListInicioItem(){
con = new conexion(getActivity(), "bd_C", null, 1);
bd=con.getReadableDatabase();
try {
String query="Select * from " + Inicio.TInicio +" where Id= '"+id+"'";
Cursor cursor = bd.rawQuery(query, null);
if (cursor != null) {
if (cursor.moveToFirst() == true) {
do {
for (int i = 0; i < cursor.getCount(); i++) {
inicio = listCreditos.get(i);
arrayList.add(new InicioItem(inicio));
}
} while (cursor.moveToNext());
}
}
cursor.close();
}
catch (Exception e) {
e.toString();//Error aqui
}
bd.close();
return arrayList;
}
StartItem Class
public class InicioItem {
public InicioItem(UtilidadesSQLite inicio) {
this._inicio = inicio;
}
private UtilidadesSQLite _inicio;
public UtilidadesSQLite inicio(){
return _inicio;
}
public int imgBackground(){
int imgbackground = R.drawable.background_item_red;
if(_inicio != null){
switch (Integer.parseInt(_inicio.Estatus)){
case 0:
imgbackground = R.drawable.background_item_red;
break;
case 1:
imgbackground = R.drawable.background_item_teal;
break;
case 2:
imgbackground = R.drawable.background_item_blue;
break;
}
}
return imgbackground;
}
public int img(){
int img = R.drawable.ic_item_no_asignado;
try{
if(_inicio != null){
switch (Integer.parseInt(_inicio.Estatus)){
case 0:
img = R.drawable.ic_item_no_asignado;
break;
case 1:
img = R.drawable.ic_item_activo;
break;
case 2:
img = R.drawable.ic_item_convenio_promesa_pago;
break;
}
}
}catch (Exception e){
e.printStackTrace();
}
return img;
}
public String nombre(){
if(_inicio != null)
return _inicio.Nombre.toUpperCase();
return "No hay registro";
}
}
Thank you!