2

我正在尝试使用客户端服务器在屏幕上显示图像,但出现异常

找不到协议:net.rim.device.cldc.io.ftp.Protocol",java.lang.IllegalArgumentException。

在这里,我发布了出现异常的代码(目前在应用程序上我成功使用客户端服务器登录,显示文件夹和目录,现在我想单击它在新屏幕上打开的任何文件。)

package com.rim.samples.device.mapactiondemo;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;

public class ShowData extends MainScreen {

String connParams;

public ShowData() {

    // Check Type of connection
    CheckConnection obj1 = new CheckConnection();
    connParams = obj1.getConnParam();

    Bitmap listThumb;

    String path = "ftp://dice:pAssw0rd@64.207.149.236:21/images/facebook.png"
        + connParams + "";

    listThumb = getImage.getImageFromUrl(path);

    BitmapField bitmapField1 = new BitmapField(listThumb);
    add(bitmapField1);

}

}

获取图像.java

package com.rim.samples.device.mapactiondemo;

import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;
import java.io.IOException;
import java.io.InputStream;
import java.lang.String;
import net.rim.device.api.system.Bitmap;

public final class getImage {

/**
 * Fetches the content on the speicifed url. The url of the content to fetch
 */

public static Bitmap getImageFromUrl(String url) {
    Bitmap bitmap = null;

    try {
        String bitmapData = getDataFromUrl(url);
        bitmap = Bitmap.createBitmapFromBytes(bitmapData.getBytes(), 0,
                bitmapData.length(), 1);
        // Image.createImage(imageData.getBytes(), 0,imageData.length());
    } catch (Exception e1) {
        e1.printStackTrace();
        System.out.println(e1);
    }

    return bitmap;
}

/**
 * Fetches the content on the speicifed url. The url of the content to fetch
 */
private static String getDataFromUrl(String url) {
    StringBuffer b = new StringBuffer();
    InputStream is = null;

    SocketConnection c = null;

    long len = 0;
    int ch = 0;

    try {
        c = (SocketConnection) Connector.open(url);
        c.setSocketOption(SocketConnection.LINGER, 5);
        c.setSocketOption(SocketConnection.DELAY, 5);

        is = c.openInputStream();
        //len = is.getLength();
        if (len != -1) {
            // Read exactly Content-Length bytes
            for (int i = 0; i < len; i++)
                if ((ch = is.read()) != -1) {
                    b.append((char) ch);
                }
        } else {
            // Read until the connection is closed.
            while ((ch = is.read()) != -1) {
                len = is.available();
                b.append((char) ch);
            }
        }

        is.close();
        c.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return b.toString();
}

}
4

1 回答 1

1

据我所知 ftp 协议未在 BlackBerry Java SDK 中实现。使用 http 协议而不是 ftp。

于 2013-09-17T12:04:44.653 回答