2

I am trying to show image on screen by using client server, but I got exception

Protocol not found: net.rim.device.cldc.io.ftp.Protocol" , java.lang.IllegalArgumentException.

Here I have post the code where I get the exception(Currently on app I successfully login with client server, show folders & directories, now I want to click on any file it open on new screen.)

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

}

}

getImage.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();
}

}
Nate
  • 31,017
  • 13
  • 83
  • 207
Kabir Somro
  • 125
  • 7
  • why you using ftp. you can use http://your_site.com/images/facebook.png na ? – Rince Thomas Sep 17 '13 at 11:37
  • 1
    Because the complete data come from desktop server, i can access it by using socket connection. On forums & other places i see the syntax for retrieve the data from server "ftp://user:password@host:port/path". – Kabir Somro Sep 17 '13 at 12:30
  • 1
    Please obscure usernames and passwords when posting sample code ... – Michael Donohue Sep 18 '13 at 05:38
  • @MichaelDonohue, here I only give child user username & password. – Kabir Somro Sep 18 '13 at 07:09
  • @Nate, is there any way I used to fix that issue? Basically it is a client server app. – Kabir Somro Sep 18 '13 at 07:14
  • @Signare, I am using SocketConnection to login with ftp client server like a "URL = "socket://" + host + ':' + Integer.toString(port);", How I can use SocketConnection with to display specific image on screen ? – Kabir Somro Sep 18 '13 at 10:41

1 Answers1

1

As far as I know ftp protocol is not implemented in BlackBerry Java SDK. Use http protocol instead of ftp.

  • First, i have using http protocol(HttpConnection) but it returns null , when it come **c = (HttpConnection) Connector.open(url); ** it goes on exception block. – Kabir Somro Sep 17 '13 at 12:33
  • Basically, i retrieve this data from desktop server, i thing for this i need socket connection. In app, successfully i create socket connection, display all files & directories, but now i want when i click on any file like image it display on new screen. – Kabir Somro Sep 17 '13 at 12:36
  • 1
    @Kabir you said "Basically, i retrieve this data from desktop server, i thing for this i need socket connection". You are correct, if you wish to use an ftp server, then you will need to open a socket and implement the ftp protocol yourself, since it is not supported by any Blackberry supplied code. – Peter Strange Sep 17 '13 at 13:02
  • @PeterStrange can you provide any help/idea now how i can retrieved data to show on new screen, I try to solve it but not get any success. – Kabir Somro Sep 17 '13 at 13:54
  • 1
    @Kabir - I am not sure what you mean. The ftp protocol defines how. I thought you had already read the ftp protocol documentation and implemented some if it, since you appear to be using it to display directories. So the follow on is just to implement more of the specification. From memory, downloading involves you requesting a file and getting a port - open that to retrieve the data. – Peter Strange Sep 18 '13 at 09:45
  • @PeterStrange, this thing I achieved in android, in android I am using the url "user:password@host:port/path" to retrieve/show any file like a video, images etc from client server. This app is complete for android but when I use this url to retrieve/show the data from client server I get exception. – Kabir Somro Sep 18 '13 at 10:05
  • @PeterStrange, You say "I am not sure what you mean." I have receives all folder, files & directories from client server in tree view like a file manager. Now when I click on image flder that shows all images then when I click on any image file it must be shows in new screen(at this point I got the exception). – Kabir Somro Sep 18 '13 at 10:16