×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Download image with emulator s60

    Hi.. guys

    I got a trouble for downloading an image. The size of the image is about 300 kB. And here is the error message:

    IOException java.io.IOException: SymbianOS error = -34 : System:System error

    And, here is my simple source code:

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.io.*;
    import java.io.*;

    public class ViewPng extends MIDlet implements CommandListener
    {
    private Display display;
    private TextBox tbMain;
    private Form fmViewPng;
    private Command cmExit, cmView, cmBack;

    public ViewPng()
    {
    display = Display.getDisplay(this);

    tbMain = new TextBox("Enter url", "http://localhost/webservice/peta.png", 75, 0);

    cmExit = new Command("Exit", Command.EXIT, 1);
    cmView = new Command("View", Command.SCREEN, 2);
    tbMain.addCommand(cmExit);
    tbMain.addCommand(cmView);

    tbMain.setCommandListener(this);

    fmViewPng = new Form("");

    cmBack = new Command("Back", Command.BACK, 1);
    fmViewPng.addCommand(cmBack);

    fmViewPng.setCommandListener(this);
    }

    public void startApp()
    {
    display.setCurrent(tbMain);
    }

    public void pauseApp() {}

    public void destroyApp (boolean unc) {}

    public void commandAction (Command c, Displayable d)
    {
    if (c == cmExit)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    else if (c == cmView)
    {
    try
    {
    Image im;
    if ((im = getImage(tbMain.getString())) != null)
    {
    ImageItem ii = new ImageItem(null, im, ImageItem.LAYOUT_DEFAULT, null);

    if (fmViewPng.size() != 0)
    {
    fmViewPng.set(0, ii);
    }
    else
    {
    fmViewPng.append(ii);
    }
    }
    else
    {
    fmViewPng.append("download gagal");
    }

    display.setCurrent(fmViewPng);
    }
    catch (Exception e)
    {
    System.err.println("Msg: "+ e.toString());
    }
    }
    else if (c == cmBack)
    {
    display.setCurrent(tbMain);
    }
    }

    private Image getImage(String url) throws IOException
    {
    ContentConnection connection = (ContentConnection) Connector.open(url);
    DataInputStream iStrm = connection.openDataInputStream();

    Image im = null;

    try
    {
    // ContentConnection includes a length method
    byte imageData[];
    int length = (int) connection.getLength();
    if (length != -1)
    {
    imageData = new byte[length];

    // Read the png into an array
    iStrm.readFully(imageData);
    }
    else // Length not available...
    {
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

    int ch;
    while ((ch = iStrm.read()) != -1)
    bStrm.write(ch);

    imageData = bStrm.toByteArray();
    bStrm.close();
    }

    // Create the image from the byte array
    im = Image.createImage(imageData, 0, imageData.length);
    }
    finally
    {
    // Clean up
    if (iStrm != null)
    iStrm.close();
    if (connection != null)
    connection.close();
    }
    return (im == null ? null : im);
    }
    }

    From my source code, where is the problem?

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Download image with emulator s60

    hi,

    your code is simliar to one I used to learn download process:
    http://www-128.ibm.com/developerworks/library/j-j2me4/
    except of fact that you are not using Thread for blocking i/o operation like donwload process,

    that Symbian errors means "Failed to connect":
    http://www.newlc.com/article.php3?id_article=117

    regards,
    Peter

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Re: Download image with emulator s60

    I'm sorry. Yup, I get the source code to learn download process.

    So, how I use thread to fix the problem? I am still confuse about it. Can you tell me more specific about this problem?

    Thx you so much friend..

    regards,

    jen_fu

  4. #4
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Download image with emulator s60

    hi,

    if you are using S603rd edition SDK have you been prompted to allow network connection (via winsock)?

    regards,
    Peter

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Re: Download image with emulator s60

    hi..

    I use s60 2nd edition SDK. And I run this application from tab run in WTK console.

    How to allow network connection via winsock?

    Is it need change the ethernet setting in preference? if yes, what kind of setting? Is the emulator's IP address should be member of my PC's IP address (in same subnet mask)?
    And how about the proxy server?

    thx...

  6. #6
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Download image with emulator s60

    hi,

    #1
    I've never managed to configure tcp/ip connections in S60 2rdEd FP2 SDK emulator, so I always use 3rdEd emulator for tcp/ip, sorry,

    #2
    what are threads and how to use them in midp (resources):
    http://discussion.forum.nokia.com/fo...hlight=threads

    hth,
    regards,
    Peter

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Re: Download image with emulator s60

    Hi,

    OK. If you use s60 3rd Edition, how to setting the tcp/ip so it can connect to server and can download something? I may try to use s60 3rd Edition to run download application.

    So, the problem is not in the source code, is it? Or is the problem from the emulator's setting?

    Thanx.

    Regards,

    jen_fu

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    17

    Re: Download image with emulator s60

    hi,

    I've tried to change IP address in ethernet setting of emulator s60 2nd Ed as part of network with my PC (in the same subnet mask of my PC). But it still doesn't work.

    Is the problem in the code or in emulator's setting?

    Thx..

    regards,

    jen_fu

Similar Threads

  1. Opening a JPEG Image
    By ummarbhutta in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-02-15, 06:34
  2. how to cut some part of Image
    By mshouab in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-08-04, 09:05
  3. HELP: Mutable Image to Immutable Image?
    By rj_cybersilver in forum Mobile Java Media (Graphics & Sounds)
    Replies: 1
    Last Post: 2005-03-26, 09:58
  4. Replies: 1
    Last Post: 2003-04-19, 22:28

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×