不兼容的类型:ArrayList<String>无法转换为字符串 [英] incompatible types: ArrayList&lt;String&gt; cannot be converted to String

查看:43
本文介绍了不兼容的类型: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(){

这篇关于不兼容的类型:ArrayList<String>无法转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆