0

我开发了一个 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 originalie传入时["6AF4B1EAC8D8210D64A944BFD487B9F2"],我得到一个错误:

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

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

4

2 回答 2

0

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

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

于 2013-09-23T09:06:07.447 回答
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;
}
于 2013-09-24T03:16:58.230 回答