【问题标题】:Java Android stringToList: undefined type - guavaJava Android stringToList:未定义类型 - 番石榴
【发布时间】:2012-03-10 03:11:06
【问题描述】:

我正在开发 Android SDK-NDK,但遇到以下代码问题:

            case ColorArray:
                List<Color> lIdList = stringToList
                (   new Function<String, Color>() 
                    {
                        public Color apply(String pSubValue) 
                        {   return new Color(pSubValue);
                        }
                    }, 
                    lValue
                );
                break;

这是 Eclipse IDE 在 FC16 上给出的消息:

The method stringToList(new Function<String,Color>(){}, String) is undefined for the type StoreActivity

为了解决这个问题,我已经包括:

import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.primitives.Ints;

import java.util.ArrayList;
import java.util.List;

我还在项目 > 属性 > Java 构建路径 > 库中添加了“guava-11.0.1.jar”。

但问题并没有消失。

非常感谢所有 cmets 和建议。

【问题讨论】:

    标签: android string list undefined guava


    【解决方案1】:

    StoreActivity 类没有使用此签名 (stringToList(new Function&lt;String,Color&gt;(){}, String)) 定义的 stringToList 方法,是吗?

    【讨论】:

    • 我什至不知道您希望该功能来自何处,OP。
    【解决方案2】:

    @Xaerxess 和 Louis Wasserman

    你是对的。方法定义是运行代码所缺少的。序列中定义了stringToList方法:

    private <TType> List<TType> stringToList(
                    Function<String, TType> pConversion,
                    String pValue) {
        String[] lSplitArray = pValue.split(";");
        List<String> lSplitList = Arrays.asList(lSplitArray);
        return Lists.transform(lSplitList, pConversion);
    }
    

    它解决了这个问题。感谢您的宝贵意见和评论。

    【讨论】:

    • 哇。匈牙利表示法太难读了:/我很高兴我们摆脱了它,这要归功于我们的类型系统和 IDE。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多