Solved

Read Image - JavaME

Posted on 2011-02-13
20
294 Views
Last Modified: 2013-11-24
What other api can i use to create images beside createimage? I am using Blackberry and J2ME.

Image image = Image.createImage(input);
0
Comment
Question by:bbdriver
  • 10
  • 8
20 Comments
 
LVL 92

Expert Comment

by:objects
ID: 34885444
what problem are you having with createImage()?
Whats 'input'?
0
 

Author Comment

by:bbdriver
ID: 34885674
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 34885683
none that I'm aware of.
0
 

Author Comment

by:bbdriver
ID: 34885691
Do you have any idea why the program will stop when i try to use createImage() without throwing any exception?
0
 

Author Comment

by:bbdriver
ID: 34885730
I am able to open it in phone imageviewer but it can't be processed using my program.
0
 
LVL 92

Expert Comment

by:objects
ID: 34885751
could be a deadlock, hard to say without see your code
0
 

Author Comment

by:bbdriver
ID: 34885760
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();
0
 

Author Comment

by:bbdriver
ID: 34885788
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.hasMoreElements()) {
                                    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.toString());
                              return;
                        }
                        catch (IOException e)
                        {
                              errorDialog("IO EXCEPTION: " + e.toString());
                              return;
                        }      
                        catch(Exception e){
                              errorDialog("EXCEPTION" + e.toString() );
                        }                  
                  }
            }
0
 

Author Comment

by:bbdriver
ID: 34885846
I am not sure if it's deadlock. It doesn't look like it.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 92

Expert Comment

by:objects
ID: 34885909
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
0
 

Author Comment

by:bbdriver
ID: 34885994
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.
0
 
LVL 92

Expert Comment

by:objects
ID: 34886012
If you get an exception, you try and open the connection again
0
 

Author Comment

by:bbdriver
ID: 34886064
I have tried that and got FileIOException,

I am  trying this..


try {
                                                updateContent("" + input);
                                                Logger.logEventInfo("READING1: " + imageName);
                                                Image image = Image.createImage(input);            
                                                Logger.logEventInfo("READING2: " + 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("READING4: " + imageName +"\n");
                                                toJSON(outer, "Caught IOException:" + description, "filename:" + imageName);
                                                
                                          } catch (Exception e)  {

                                                Exceptiondescription = e.toString();
                                                updateContent("READING: " + imageName);      
                                                Logger.logEventInfo("READING5: " + 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
0
 
LVL 92

Expert Comment

by:objects
ID: 34886100
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?
0
 

Author Comment

by:bbdriver
ID: 34886156
I don't think it's exiting the method. How do I log the detail of exception?
0
 
LVL 92

Expert Comment

by:objects
ID: 34892133
> 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
0
 

Accepted Solution

by:
bbdriver earned 0 total points
ID: 34894167
Hi.. i think i got it. I have changed Image image = Image.createImage(input); to byte[] b3=str.getBytes();
                                                Image image = Image.createImage(b3, 0, 0);

And it works now. I think there are is some issue with just create image with input stream.
0
 
LVL 92

Expert Comment

by:objects
ID: 34902211
may have been a problem with the input stream,
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 37514365
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java / Linux and Regular Expressions 11 70
Java - Why doesn't this JFrame work 3 41
stackato and cloud 4 69
print map entry 34 55
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now