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

查看:85
本文介绍了不兼容的类型:ArrayList< String>无法转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看不到我的ArrayList出了什么问题,我得到了这个错误:

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

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

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;
    }

推荐答案

返回值 arrTblNames 的类型为 ArrayList ,但返回类型为 getListOfFiltersName String ,因此出现错误,因此 getListOfFiltersName 方法的返回类型应为 ArrayList< String> 而不是 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 List< String>getListOfFiltersName(){

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

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