Why returning values from sqlite returns an empty array

user3600801

Im using the following code to add values to db.

public void addComplianceAcceptability(ComplianceAcceptability complianceAcceptability) {
    SQLiteDatabase sqLiteDatabase = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();

    contentValues.put(KEY_ID, complianceAcceptability.getId());
    contentValues.put(KEY_COUNTRY_ID, complianceAcceptability.getCountryId());
    contentValues.put(KEY_DOMAIN_ID, complianceAcceptability.getDomainId());
    contentValues.put(KEY_UNIT_ID, complianceAcceptability.getUnitId());
    contentValues.put(KEY_COMPLIANCE_ID, complianceAcceptability.getComplianceId());
    contentValues.put(KEY_COMPLIANCE_NAME, complianceAcceptability.getCompliancenName());
    contentValues.put(KEY_COMPLIANCE_FREQUENCY, complianceAcceptability.getComplianceFrequency());
    contentValues.put(KEY_COMPLIANCE_APPLICABLE, complianceAcceptability.getComplianceApplicable());
    contentValues.put(KEY_COMPLIANCE_OPTED, complianceAcceptability.getComplianceOpted());

    sqLiteDatabase.insert(TABLE_COMPLIANCE_ACCEPTABILITY, null, contentValues);
    sqLiteDatabase.close();
}

Imm trying to access the values using the following code,

public List<ComplianceAcceptability> getAllAcceptability() {

        List<ComplianceAcceptability> complianceAcceptabilityList = new ArrayList<>();

        String selectQuery = "SELECT * FROM " + TABLE_COMPLIANCE_ACCEPTABILITY;

        SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

        if (cursor.moveToFirst()) {
            do {
                ComplianceAcceptability complianceAcceptability = new ComplianceAcceptability();

                complianceAcceptability.setId(Integer.parseInt(cursor.getString(0)));
                complianceAcceptability.setCountryId(cursor.getString(1));
                complianceAcceptability.setDomainId(cursor.getString(2));
                complianceAcceptability.setUnitId(cursor.getString(3));
                complianceAcceptability.setComplianceId(cursor.getString(4));
                complianceAcceptability.setCompliancenName(cursor.getString(5));
                complianceAcceptability.setComplianceFrequency(cursor.getString(6));
                complianceAcceptability.setComplianceApplicable(cursor.getString(7));
                complianceAcceptability.setComplianceOpted(cursor.getString(8));

            } while (cursor.moveToNext());
        }

        return complianceAcceptabilityList;
    }

The problem is that it returns an empty array. But when I try to print the contentValues within addComplianceStatus, it of course prints the array of all values.

Doug Stevenson

You never add anything to complianceAcceptabilityList. You just assign it once, then do nothing to it before returning it. Maybe you want to add complianceAcceptability into it at each iteration through the cursor?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Global array returns empty with values from .push

Why the array returning empty spaces

Why is slice returning an empty array?

why does a Uint8Array() from buffer returns empty?

Why is this function returns an empty array?

Why is GetMetricData returning an empty set of values?

Javascript map question returning an array with empty values

Empty Values is returning to an array using express

Why PHP get empty array from checkbox with the dynamic values?

Why is this simple filter returning an empty array?

Why is mongoose.find returning an empty Array

Why is this get_pages returning an empty array?

Why is this regexp returning an empty item at the beginning of the array?

Why is IJavaProject.findPackageFragmentRoots returning an empty array?

Why is consul health check returning an empty array?

Why is stack_data() returning an empty array?

Why is my array is returning to the test empty?

Why is my function returning an empty array?

Returning values from array separately

Why the sqlite cursor in android returns different values?

Why I am getting random values from array in a function when returning an array from a function as an argument?

Why is this async function returning empty on the first try, but then it returns everything?

Why the below function is not returning any value and it is always returns empty

Returning empty array from generic function

Custom Hook Returning Empty Array From Firestore

useState from API returning an empty array

Why Laravel query returns empty array?

Array is passed as an argument in function and accessed,So Why does the values of array gets modified after returning from function?

filtering an array of objects based on another array of values, returning an empty list