473,403 Members | 2,293 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,403 software developers and data experts.

runtime error during downloading images from server to mobile

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



i´m grateful for every hint and solution!
surja
Jan 2 '08 #1
0 909

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...
11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
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...
4
by: surja | last post by:
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.