I create a database and in the static class I keep the names of the fields and field types. When creating the first two tables, no problems occur, but for some reason this error pops up when creating the following tables.

static class code:

public static abstract class FirmsEntry implements BaseColumns{ public static final int IS_ON_INDEX = 0; public static final int IS_OFF_INDEX = 1; public static final String COLUMN_FIRM_ID = "firm_id"; public static final String COLUMN_NAME = "firm_name"; public static final String COLUMN_DESCR = "firm_descr"; public static final String COLUMN_RATING = "firm_rating"; public static final String COLUMN_IS_ON = "firm_is_on"; public static final String[] COLUMNS = new String[] { _ID, COLUMN_FIRM_ID, COLUMN_NAME, COLUMN_DESCR, COLUMN_RATING, COLUMN_IS_ON}; public static final String[] TYPES = new String[] { TYPE_PRIMARY_KEY, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_TEXT, TYPE_INT}; } 

Appeal to him:

 db.execSQL(createTable(UserContract.TABLE_NAME_FIRMS, FirmsEntry.COLUMNS, FirmsEntry.TYPES)); 

CreateTable method:

 private String createTable(String tableName, String[] columns, String[] types) { if (tableName == null || columns == null || types == null || types.length != columns.length || types.length == 0) { throw new IllegalArgumentException( "Invalid parameters for creating table " + tableName); } else { StringBuilder stringBuilder = new StringBuilder("CREATE TABLE "); stringBuilder.append(tableName); stringBuilder.append(" ("); for (int n = 0, i = columns.length; n < i; n++) { if (n > 0) { stringBuilder.append(", "); } stringBuilder.append(columns[n]).append(' ') .append(types[n]); } return stringBuilder.append(");").toString(); } } 
  • Is a static class inside another class? or in a separate file? If all of the sudden the second, then you probably should remove the static in the class definition, because "You can also declare a class static, except for the top-level classes. Such classes are known as" nested static class ". - I . Smirnov
  • @ I.Smirnov inside another class - makavelka

0