android – Not showing data from SQLite in LISTVIEW-ThrowExceptions

Exception or error:

I am getting data from SQLite and showing it in list view but it is not working ,

The same same is working fine with recycle view but not with list view,

Can someone will help me where i am getting wrong.

I have tried many different options but nothing is working.

//Main Class

public class DeviceScanActivity extends ListActivity{

SQLiteDatabase mDatabase;
DatabaseHelper databaseHelper;
private LeDeviceListAdapter mLeDeviceListAdapter;
 .................

    databaseHelper = new DatabaseHelper(this);
    mDatabase = databaseHelper.getWritableDatabase();

    mLeDeviceListAdapter = new LeDeviceListAdapter(this, getAllItems());

    setListAdapter(mLeDeviceListAdapter);



private Cursor getAllItems() {

    Cursor cursor = mDatabase.query(TABLE_NAME,
            new String[] {COL1, COL2, COL3, COL4, COL5},
            null, null, null, null, null);
    cursor.moveToFirst();
    return cursor;

}



}

//Listview adapter

public class LeDeviceListAdapter extends BaseAdapter {
  private Cursor accounts;

  SQLiteDatabase db;
  public View getView(int i, View view, ViewGroup viewGroup) {
    ViewHolder viewHolder;
    // General ListView optimization code.
    if (view == null) {
        view = mInflator.inflate(R.layout.listitem_device, null);
        viewHolder = new ViewHolder();
        viewHolder.deviceAddress = view
                .findViewById(R.id.device_address);
        viewHolder.deviceName = view
                .findViewById(R.id.device_name);
        viewHolder.deviceState = view
                .findViewById(R.id.device_state);
        viewHolder.deviceRssiRslt = view
                .findViewById(R.id.deviceTestResult);
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }

    TIBLEPerperal device = mContext.getBlePerp(i);
    if (device == null) {
        return null;
    }


    final String id = accounts.getString(accounts.getColumnIndex(COL1));
    final String beaconname = accounts.getString(accounts.getColumnIndex(COL2));
    final String BEACONTYPE = accounts.getString(accounts.getColumnIndex(COL3));
    final String BEACONCONN = accounts.getString(accounts.getColumnIndex(COL4));
    final String BEACONMAC = accounts.getString(accounts.getColumnIndex(COL5));

    if (id!=null){
        viewHolder.deviceName.setText(beaconname);
    }
}
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *