不兼容的类型:ArrayList无法转换为字符串

不兼容的类型:ArrayList<String>无法转换为字符串

问题描述:

我没有看到我的 ArrayList 有什么问题,我收到了这个错误:

I don't see what is wrong with my ArrayList that i get this error:

错误:(133, 17) 错误:类型不兼容:ArrayList 不能为转换为字符串

Error:(133, 17) error: incompatible types: ArrayList cannot be converted to String

我想从表名中获取所有列

i want to get all columns from table name

   public String getListOfFiltersName(){

        ArrayList<String> arrTblNames = new ArrayList<String>();
        Cursor c = mydb.rawQuery("SELECT name FROM  " + MyDatabase.tableFilters, null);

        if (c.moveToFirst()) {
            while ( !c.isAfterLast() ) {
                arrTblNames.add( c.getString( c.getColumnIndex("name")) );
                c.moveToNext();
            }
        }
        c.close();
        mydb.close();
        return  arrTblNames;
    }

返回值的类型 arrTblNamesArrayList 但返回类型是 getListOfFiltersNameString 因此错误所以 getListOfFiltersName 方法的返回类型应该是 ArrayList 而不是 String

The type of returned value arrTblNames is ArrayList but the return type of getListOfFiltersName is String Hence the error so return type of getListOfFiltersName method should be ArrayList<String> instead of String

public ArrayList<String> getListOfFiltersName(){

或者最好是public ListgetListOfFiltersName(){