473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

runtime error during downloading images from server to mobile

5
Hi,
I have written a code to download images from a server end desktop,
but while running the code ,WTK is showing a runtime error " Create image from Byte array
Uncaught exception java/lang/IllegalArgumentException: ".
I cannot detect the necessary change I have to make to run my code succesfully.Please anyone can help me to solve this code

Expand|Select|Wrap|Line Numbers
  1. /code/
  2. import javax.microedition.midlet.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.io.*;
  5. import java.io.*;
  6. import java.util.*;
  7. import javax.microedition.io.HttpConnection;
  8.  
  9. public class DownloadImage extends MIDlet implements CommandListener
  10. {
  11.  private Command exit,start;
  12.  public Display display;
  13.  private Form form;
  14.  private StringItem stars;
  15.  
  16.  public DownloadImage()
  17.  {
  18.    display = Display.getDisplay(this);
  19.    exit = new Command("Exit",Command.EXIT,1);
  20.    start = new Command("start",Command.SCREEN,1);
  21.    form = new Form("Picture");
  22.    form.addCommand(exit);
  23.    form.addCommand(start);
  24.    form.setCommandListener(this);
  25.  
  26.  }
  27.  
  28.  
  29.  public void startApp() throws MIDletStateChangeException
  30.  {
  31.    //display.setCurrent(form);//
  32.    if(display==null)
  33.     display=Display.getDisplay(this);
  34.      display.setCurrent(form);
  35.      System.out.println("start");
  36.  
  37.      //Do network loading in separate thread
  38.  
  39.  
  40.  }
  41.  
  42.  public void pauseApp()
  43.  {
  44.  }
  45.  
  46.  public void destroyApp(boolean unconditional)
  47.  {
  48.  }
  49.  
  50.  public void commandAction(Command command,Displayable displayable)
  51.   {
  52.    if(command == exit)
  53.    {
  54.     destroyApp(false);
  55.     notifyDestroyed();
  56.    }
  57.     else if (command == start)
  58.     {
  59.         Form wform=new Form("picture1");
  60.         display.setCurrent(wform);
  61.         System.out.println("command");
  62.  
  63.         Thread t=new Thread()
  64.         {
  65.             public void run()
  66.               {
  67.                  connect();
  68.                  System.out.println("connect");
  69.                }
  70.          };t.start();
  71.  
  72.      }
  73.  
  74.    }
  75.    public void connect()
  76.    {
  77.      ContentConnection connection = null;
  78.  
  79.      //InputStream inputstream = null;
  80.           Image image = null;
  81.  
  82.  
  83.     try
  84.  
  85.       {
  86.           System.out.println("connection");
  87.     connection = (ContentConnection)Connector.open("http://172.24.182.155:8080/surja/logo.png");
  88.           System.out.println("retreive");
  89.      //InputStream inputstream = (InputStream)Connector.openInputStream(connection);
  90.           DataInputStream inputstream = connection.openDataInputStream();
  91.  
  92.         ByteArrayOutputStream bytearray = new ByteArrayOutputStream();
  93.         int ch;
  94.         while ((ch = inputstream.read()) != -1)
  95.          {
  96.              bytearray.write(ch);
  97.              System.out.println("read");
  98.           }
  99.  
  100.          byte imagearray[] = bytearray.toByteArray();
  101.  
  102.          //Create image from Byte array
  103.             System.out.println("Create image from Byte array");
  104.          image = image.createImage(imagearray,0,imagearray.length);
  105.          //form.append(image);
  106.            System.out.println("Image created");
  107.        }
  108.        catch (IOException error)
  109.        {
  110.         Alert alert = new Alert("Error","Cannnot connect"+ error,null,null);
  111.         alert.setTimeout(Alert.FOREVER);
  112.         alert.setType(AlertType.ERROR);
  113.         display.setCurrent(alert);
  114.  
  115.        }
  116.     }
  117.  
  118.  
  119.    //}
  120.  }/CODE/

i´m grateful for every hint and solution!
surja
Dec 28 '07 #1
4 1595
RedSon
5,000 Expert 4TB
We have [CODE] tags [/code] for a reason... Please use them.

Moved from the mobile forum.
Dec 28 '07 #2
BigDaddyLH
1,216 Expert 1GB
Check: What is the value of imagearray.length? Is it > 0?
Dec 28 '07 #3
surja
5
runtime error during downloading images from server to mobile
--------------------------------------------------------------------------------

Hi,
I have written a code to download images from a server end desktop,
but while running the code ,WTK is showing a runtime error " Create image from Byte array
Uncaught exception java/lang/IllegalArgumentException: ".
I cannot detect the necessary change I have to make to run my code succesfully.Please anyone can help me to solve this code


Code: ( java )


Expand|Select|Wrap|Line Numbers
  1.  
  2. import javax.microedition.midlet.*;
  3. import javax.microedition.lcdui.*;
  4. import javax.microedition.io.*;
  5. import java.io.*;
  6. import java.util.*;
  7. import javax.microedition.io.HttpConnection;
  8.  
  9. public class DownloadImage extends MIDlet implements CommandListener
  10. {
  11.  private Command exit,start;
  12.  public Display display;
  13.  private Form form;
  14.  private StringItem stars;
  15.  
  16.  public DownloadImage()
  17.  {
  18.    display = Display.getDisplay(this);
  19.    exit = new Command("Exit",Command.EXIT,1);
  20.    start = new Command("start",Command.SCREEN,1);
  21.    form = new Form("Picture");
  22.    form.addCommand(exit);
  23.    form.addCommand(start);
  24.    form.setCommandListener(this);
  25.  
  26.  }
  27.  
  28.  
  29.  public void startApp() throws MIDletStateChangeException
  30.  {
  31.    //display.setCurrent(form);//
  32.    if(display==null)
  33.     display=Display.getDisplay(this);
  34.      display.setCurrent(form);
  35.      System.out.println("start");
  36.  
  37.      //Do network loading in separate thread
  38.  
  39.  
  40.  }
  41.  
  42.  public void pauseApp()
  43.  {
  44.  }
  45.  
  46.  public void destroyApp(boolean unconditional)
  47.  {
  48.  }
  49.  
  50.  public void commandAction(Command command,Displayable displayable)
  51.   {
  52.    if(command == exit)
  53.    {
  54.     destroyApp(false);
  55.     notifyDestroyed();
  56.    }
  57.     else if (command == start)
  58.     {
  59.         Form wform=new Form("picture1");
  60.         display.setCurrent(wform);
  61.         System.out.println("command");
  62.  
  63.         Thread t=new Thread()
  64.         {
  65.             public void run()
  66.               {
  67.                  connect();
  68.                  System.out.println("connect");
  69.                }
  70.          };t.start();
  71.  
  72.      }
  73.  
  74.    }
  75.    public void connect()
  76.    {
  77.      ContentConnection connection = null;
  78.  
  79.      //InputStream inputstream = null;
  80.           Image image = null;
  81.  
  82.  
  83.     try
  84.  
  85.       {
  86.           System.out.println("connection");
  87.     connection = (ContentConnection)Connector.open("http://172.24.182.155:8080/surja/logo.png");
  88.           System.out.println("retreive");
  89.      //InputStream inputstream = (InputStream)Connector.openInputStream(connection)  ;
  90.           DataInputStream inputstream = connection.openDataInputStream();
  91.  
  92.         ByteArrayOutputStream bytearray = new ByteArrayOutputStream();
  93.         int ch;
  94.         while ((ch = inputstream.read()) != -1)
  95.          {
  96.              bytearray.write(ch);
  97.              System.out.println("read");
  98.           }
  99.  
  100.          byte imagearray[] = bytearray.toByteArray();
  101.  
  102.          //Create image from Byte array
  103.             System.out.println("Create image from Byte array");
  104.          image = image.createImage(imagearray,0,imagearray.length);  
  105.          //form.append(image);
  106.            System.out.println("Image created");
  107.        }
  108.        catch (IOException error)
  109.        {
  110.         Alert alert = new Alert("Error","Cannnot connect"+ error,null,null);
  111.         alert.setTimeout(Alert.FOREVER);
  112.         alert.setType(AlertType.ERROR);
  113.         display.setCurrent(alert);
  114.  
  115.        }
  116.     }
  117.  
  118.  
  119.    //}
  120.  }


i´m grateful for every hint and solution!
surja
Dec 31 '07 #4
RedSon
5,000 Expert 4TB
Come on surja!

Are you just not paying attention or something? First you posted in the wrong forum, then you don't use code tags, then you double post in the wrong form again. Now I have merged your posts! I am losing patience.

Please be warned to not muck up the forums again by reposting this question again in the wrong forum.
Dec 31 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
2
by: VB Programmer | last post by:
I only have 1 set of <FORM> tags in my HTML file, but I keep getting this error. Any ideas? *********** A page can have only one server-side Form tag. Description: An unhandled exception...
14
by: Rich | last post by:
I am converting my enterprise solution from VS 2003 (.NET v1.1.4322) to VS 2005 (.NET v2.0.50727). The entire solution uses serveral technologies - Windows Server 2003 (AD, SQL Server 2000, IIS,...
0
by: psilu | last post by:
Hi , I have created a virtual directory and copied my web services file to corresponding physical directory. But when i am trying to discover the webservice from virtual directory i am getting...
0
by: Kirk | last post by:
I'm trying to use a Web Service to be a Remoting client of an existing ..NET 2.0 server. But I get the following error when I try to use System.Runtime.Remoting.Channels.Http in my WebService. ...
1
by: mudasserrafiq | last post by:
I am using following asp file default.asp <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <META http-equiv=Content-Type content="text/html; charset=windows-1252"> <META content="0...
0
by: surja | last post by:
runtime error during downloading images from server to mobile -------------------------------------------------------------------------------- Hi, I have written a code to download images from...
0
by: cherryblossom | last post by:
hii, Im developing an client server application in C#. In that i have to use Mobile Agent technology. On the Server side there is a class...which i want send to the client...by System.IO...
3
by: graphicssl | last post by:
Okay, so first of all, I'm a designer first and a light coder second (I'm only really trained with HTML and CSS). So I apologize for having to post about something that's probably super-trivial! ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.