读取未找到BLACKBERRY / J2ME -IMAGE中的图像

时间:2011-01-10 02:10:35

标签: java blackberry java-me

我正在尝试读取SD卡上的图像。但是,当我调试代码时,它显示我: 在stacktrace上显示

I: READ STARTING
I: List of files and directories under SD CARD:
I: Image Name:image1.png
I: input Name:net.rim.device.cldc.io.file.PosixFileInputStream@76dc2ef0
IOException
No detail message
net_rim_cldc-3(4B84A78F)
 Image
 createImage
 0x52B6
W: ERROR! nulljava.io.IOException

这是我的代码:

public void readimage(){
    updateContent("READ STARTING"); 
    for(;;){
        // Thread control
        while( !_fetchStarted && !_stop){
            try{
                sleep(TIMEOUT);
            }catch (InterruptedException e){
                errorDialog("Thread#sleep(long) threw " + e.toString());
            }
        }
        // Exit condition
        if ( _stop ){
            return;
        }
        String content = "";  
        StringBuffer sb = new StringBuffer(1024);
        sb = null;
        //reading images
        try{
            FileConnection fc = 
                (FileConnection) Connector.open("file:///SDCard/BlackBerry/documents/imagefolder");
            System.out.println("List of files and directories under SD CARD:");
            Enumeration filelist = fc.list("*" , true);
            while(filelist.hasMoreElements()) {
                //imageName = (String) filelist.nextElement();
                String imageName = (String) filelist.nextElement();
                FileConnection filenames = 
                    (FileConnection) Connector.open("file:///SDCard/BlackBerry/documents/imagefolder/"
                        + imageName ,Connector.READ_WRITE);
                if(filenames.exists()){
                    content="DONE\n" + imageName;
                    System.out.println("imageName:" + imageName );
                    InputStream input = filenames.openInputStream();
                    String image_test_result = readImages(input);
        if(image_test_result.equals("OKAY") | image_test_result=="OKAY")
            content = "OKAY" 
                             + imageName.substring(imageName.indexOf("/")+1) 
                             + ",0,1," + image_test_result;
                        //logfile(pW, (image_path.substring(image_path.lastIndexOf("/")+1) + ",0,1," + image_test_result));
                    else if(image_test_result.equals("NULL") | image_test_result=="NULL")
                        content = "NULL" 
                            + imageName.substring(imageName.indexOf("/")+1) 
                            + ",0,2," + image_test_result;
                        //logfile(pW, (image_path.substring(image_path.lastIndexOf("/")+1) + ",0,2," + image_test_result));
                    else 
            content = "NULL" 
                            + imageName.substring(imageName.indexOf("/")+1)
                            + ",0,3,ERROR";
                    filenames.close();
        fc.close();                 
                }
            }
        }catch (Throwable t){
            t.printStackTrace(); 
            String errorString = t.toString();
            // content = "ERROR\n" + errorString;   
        }   
        stopStatusThread();
        updateContent(content);
        _fetchStarted = false; 
    }
}

private String readImages(InputStream input) throws IOException {
    Image image;
    image = Image.createImage(input);

    if(image!=null)
        return "OKAY";
    else 
        return "NULL";
 }

2 个答案:

答案 0 :(得分:2)

如果将捕获更改为catch (Throwable t)

,则可以获取堆栈跟踪

如果您抓住Throwable,您只能在BlackBerry应用程序上获得堆栈跟踪。任何其他类型都不会捕获堆栈跟踪。

答案 1 :(得分:0)

尝试将Connector.READ_WRITE更改为Connector.READ