详细格式化程序错误:java.util.Arrays无法解析为某种类型

时间:2013-09-23 08:25:16

标签: java arrays string blackberry blackberry-eclipse-plugin

我开发了一个BlackBerry应用程序,我正在阅读HEX String值。返回的值如下:

String result =  response.toString();

结果是: ["AC36C71DF3CB315A35BFE49A17F483B6","CF5B717ACC460E3C4545BE709E9BCB83","E1EE334738CA4FA14620639DD6750DC3","DD40E2822539C2184B652D1FC3D2B4E6","6AF4B1EAC8D8210D64A944BFD487B9F2"]

将这些传递到以下split方法中以分隔值。方法如下:

private static String[] split(String original, String separator) {
            Vector nodes = new Vector();
            int index = original.indexOf(separator);
            while (index >= 0) {
                nodes.addElement(original.substring(0, index));
                original = original.substring(index + separator.length());
                index = original.indexOf(separator);
            }
            nodes.addElement(original);
            String[] result = new String[nodes.size()];
            if (nodes.size() > 0) {
                for (int loop = 0; loop < nodes.size(); loop++) {
                    result[loop] = (String) nodes.elementAt(loop);
                    System.out.println(result[loop]);
                }
            }
            return result;
       }

传递上述数组作为方法中的String original。这部分工作正常。但是,当单个值作为String original传递时,即["6AF4B1EAC8D8210D64A944BFD487B9F2"],我收到错误:

Detail formatter error:java.util.Arrays cannot be resolved to a type

请帮忙!!!上面发布的值是读取的精确值,包括括号[]和引号""

2 个答案:

答案 0 :(得分:0)

Blackberry库基于Java ME而不是Java SE。在Java ME中,已经删除了一些类以减少运行时占用空间,例如Arrays类。

看一下Blackberry JDE java.util package,看看没有Arrays类。因此,在您的代码中,您不能使用来自Arrays类的方法,您必须找到一种解决方法或自己实现该功能。

答案 1 :(得分:0)

尝试这种拆分方法 -

 public static String[] split(String strString, String strDelimiter) {
    String[] strArray;
    int iOccurrences = 0;
    int iIndexOfInnerString = 0;
    int iIndexOfDelimiter = 0;
    int iCounter = 0;

    //Check for null input strings.
    if (strString == null) {
        throw new IllegalArgumentException("Input string cannot be null.");
    }
    //Check for null or empty delimiter strings.
    if (strDelimiter.length() <= 0 || strDelimiter == null) {
        throw new IllegalArgumentException("Delimeter cannot be null or empty.");
    }
    if (strString.startsWith(strDelimiter)) {
        strString = strString.substring(strDelimiter.length());
    }
    if (!strString.endsWith(strDelimiter)) {
        strString += strDelimiter;
    }
    while((iIndexOfDelimiter = strString.indexOf(strDelimiter,
           iIndexOfInnerString)) != -1) {
        iOccurrences += 1;
        iIndexOfInnerString = iIndexOfDelimiter +
            strDelimiter.length();
    }

    strArray = new String[iOccurrences];
    iIndexOfInnerString = 0;
    iIndexOfDelimiter = 0;
    while((iIndexOfDelimiter = strString.indexOf(strDelimiter,
           iIndexOfInnerString)) != -1) {

        strArray[iCounter] = strString.substring(iIndexOfInnerString,iIndexOfDelimiter);
        iIndexOfInnerString = iIndexOfDelimiter +
        strDelimiter.length();
        iCounter += 1;
    }

    return strArray;
}