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?

Reply With Quote

