Android error when convert month name

With this query I select the month in the database. The cursor returns the exact month, but when I do the conversion to display the full name appears the following month. For example, the cursor returns 6, instead the method returns getDisplayName July.

SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();

    String sql = "SELECT DISTINCT strftime('%m',"+Table.DATA+") FROM "+Table.TABLE_NAME;
    Cursor c = db.rawQuery(sql, null);

    while (c.moveToNext()){
        int monthNumero = (c.getInt(0));

        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.MONTH, monthNumero);
        String monthName = ca.getDisplayName
                (Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase();

        result1.add(monthName);

    }
    db.close();
Jon Skeet
people
quotationmark

For example, the cursor returns 6, instead the method returns getDisplayName July.

Yes, it would. Because the Calendar.MONTH "logical field" is 0-based. (Crazy decision, but...)

Basically you need to subtract 1 from the month number:

ca.set(Calendar.MONTH, monthNumero - 1);

For example Calendar.JANUARY is documented as having a value of 0.

people

See more on this question at Stackoverflow