bbdriver
asked on
Read Image - JavaME
What other api can i use to create images beside createimage? I am using Blackberry and J2ME.
Image image = Image.createImage(input);
Image image = Image.createImage(input);
ASKER
input is InputStream input = filenames.openInputStream( );
I have a set of images, when i use createImage(), it either returns the created image or throws IOException, Exception. But there are some images that doesn't go anywhere. I thought there might be other api that i can try out.
I have a set of images, when i use createImage(), it either returns the created image or throws IOException, Exception. But there are some images that doesn't go anywhere. I thought there might be other api that i can try out.
none that I'm aware of.
ASKER
Do you have any idea why the program will stop when i try to use createImage() without throwing any exception?
ASKER
I am able to open it in phone imageviewer but it can't be processed using my program.
could be a deadlock, hard to say without see your code
ASKER
This is the code.
FileConnection filenames = (FileConnection)Connector. open(main_ directory + "testFolder" + "/"
+ imageName ,Connector.READ);
if (filenames.exists()) { InputStream input = filenames.openInputStream( );
try { Image image = Image.createImage(input);
if(image != null){
updateContent("READING: " + imageName);
}
else continue;
}
catch (IOException e) {
updateContent("READING: " + imageName);
} catch (Exception e) {
updateContent("READING: " + imageName);
}
input.close();
}
filenames.close();
FileConnection filenames = (FileConnection)Connector.
+ imageName ,Connector.READ);
if (filenames.exists()) { InputStream input = filenames.openInputStream(
try { Image image = Image.createImage(input);
if(image != null){
updateContent("READING: " + imageName);
}
else continue;
}
catch (IOException e) {
updateContent("READING: " + imageName);
} catch (Exception e) {
updateContent("READING: " + imageName);
}
input.close();
}
filenames.close();
ASKER
public void image()
{ for(;;)
{
String content = "", description = null, Exceptiondescription=null;
JSONObject outer = new JSONObject();
try{
FileConnection fc = (FileConnection)Connector. open(main_ directory + imageFolder + "/");
FileConnection file = (FileConnection)Connector. open(main_ directory + imageFolder + ".json" ,Connector.READ_WRITE);
if(!file.exists()) { file.create(); }
file.setWritable(true);
OutputStream out = file.openOutputStream();
Enumeration filelist = fc.list("*", true);
while(filelist.hasMoreElem ents()) {
imageName = (String) filelist.nextElement();
FileConnection filenames = (FileConnection)Connector. open(main_ directory + imageFolder + "/"
+ imageName ,Connector.READ);
if (filenames.exists()) {
InputStream input = filenames.openInputStream( );
try {
Image image = Image.createImage(input);
if(image != null){
toJSON(outer, "OK", "filename:" + imageName);
}
else continue;
}
catch (IOException e) {
description = e.toString();
toJSON(outer,"Caught IOException:" + description, "filename:" + imageName);
} catch (Exception e) {
Exceptiondescription = e.toString();
toJSON(outer, " Caught Exception:" + Exceptiondescription, "filename:" + imageName);
}
input.close();
}
filenames.close();
}
file.close();
fc.close();
out.write(outer.toString() .getBytes( ));
out.flush();
out.close();
updateContent("READING: " + "COMPLETED");
}
catch (IOCancelledException e)
{
System.out.println(e.toStr ing());
return;
}
catch (IOException e)
{
errorDialog("IO EXCEPTION: " + e.toString());
return;
}
catch(Exception e){
errorDialog("EXCEPTION" + e.toString() );
}
}
}
{ for(;;)
{
String content = "", description = null, Exceptiondescription=null;
JSONObject outer = new JSONObject();
try{
FileConnection fc = (FileConnection)Connector.
FileConnection file = (FileConnection)Connector.
if(!file.exists()) { file.create(); }
file.setWritable(true);
OutputStream out = file.openOutputStream();
Enumeration filelist = fc.list("*", true);
while(filelist.hasMoreElem
imageName = (String) filelist.nextElement();
FileConnection filenames = (FileConnection)Connector.
+ imageName ,Connector.READ);
if (filenames.exists()) {
InputStream input = filenames.openInputStream(
try {
Image image = Image.createImage(input);
if(image != null){
toJSON(outer, "OK", "filename:" + imageName);
}
else continue;
}
catch (IOException e) {
description = e.toString();
toJSON(outer,"Caught IOException:" + description, "filename:" + imageName);
} catch (Exception e) {
Exceptiondescription = e.toString();
toJSON(outer, " Caught Exception:" + Exceptiondescription, "filename:" + imageName);
}
input.close();
}
filenames.close();
}
file.close();
fc.close();
out.write(outer.toString()
out.flush();
out.close();
updateContent("READING: " + "COMPLETED");
}
catch (IOCancelledException e)
{
System.out.println(e.toStr
return;
}
catch (IOException e)
{
errorDialog("IO EXCEPTION: " + e.toString());
return;
}
catch(Exception e){
errorDialog("EXCEPTION" + e.toString() );
}
}
}
ASKER
I am not sure if it's deadlock. It doesn't look like it.
you repeatedly read the same directory
and if you get an exception you don't close the connections or streams
not sure if thats the cause but worth fixing up
and if you get an exception you don't close the connections or streams
not sure if thats the cause but worth fixing up
ASKER
Does it mean that each time I get an exception, i will have to close the connection? Cause, if i close the connection, i wont be able to continue reading the next image file.
If you get an exception, you try and open the connection again
ASKER
I have tried that and got FileIOException,
I am trying this..
try {
updateContent("" + input);
Logger.logEventInfo("READI NG1: " + imageName);
Image image = Image.createImage(input);
Logger.logEventInfo("READI NG2: " + imageName);
if(image != null){
updateContent("READING3: " + imageName);
toJSON(outer, "OK", "filename:" + imageName);
}
else continue;
}
catch (IOException e) {
description = e.toString();
updateContent("READING: " + imageName);
Logger.logEventInfo("READI NG4: " + imageName +"\n");
toJSON(outer, "Caught IOException:" + description, "filename:" + imageName);
} catch (Exception e) {
Exceptiondescription = e.toString();
updateContent("READING: " + imageName);
Logger.logEventInfo("READI NG5: " + imageName);
toJSON(outer," Caught Exception:" + Exceptiondescription, "filename:" + imageName);
}
input.close();
}
filenames.close();
This is what I have in print statement. And when it reach to image3, it will stop.
I: List of files and directories under SD CARD:
I: READING1: image1.jpg
I: READING2: image1.jpg
I: READING1: image2.jpg
I: READING4: image2.jpg
I: READING1: image3.jpg
I am trying this..
try {
updateContent("" + input);
Logger.logEventInfo("READI
Image image = Image.createImage(input);
Logger.logEventInfo("READI
if(image != null){
updateContent("READING3: " + imageName);
toJSON(outer, "OK", "filename:" + imageName);
}
else continue;
}
catch (IOException e) {
description = e.toString();
updateContent("READING: " + imageName);
Logger.logEventInfo("READI
toJSON(outer, "Caught IOException:" + description, "filename:" + imageName);
} catch (Exception e) {
Exceptiondescription = e.toString();
updateContent("READING: " + imageName);
Logger.logEventInfo("READI
toJSON(outer," Caught Exception:" + Exceptiondescription, "filename:" + imageName);
}
input.close();
}
filenames.close();
This is what I have in print statement. And when it reach to image3, it will stop.
I: List of files and directories under SD CARD:
I: READING1: image1.jpg
I: READING2: image1.jpg
I: READING1: image2.jpg
I: READING4: image2.jpg
I: READING1: image3.jpg
log details of the exception to help determine why an exception is occurring
are you sure it hung and that that it isn't just exitting the method?
are you sure it hung and that that it isn't just exitting the method?
ASKER
I don't think it's exiting the method. How do I log the detail of exception?
> I don't think it's exiting the method.
add some logging to check
> How do I log the detail of exception?
log the exception including preferably the stack trace
add some logging to check
> How do I log the detail of exception?
log the exception including preferably the stack trace
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
may have been a problem with the input stream,
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Whats 'input'?