簡體   English   中英

相機問題

[英]Camera Problems

嘗試使相機正常工作時,我遇到了一些問題...相機演示在8520設備(有存儲卡)上工作,但在9780設備(無存儲卡)上不工作,出現錯誤

錯誤類java.lang.ArrayOutOfBoundsException:index 0> = 0

我的代碼示例:

public class MyScreen extends MainScreen{

    Player _p;
    VideoControl _videoControl;
    FileConnection fileconn;
    String PATH;
    String GetfileName;
    LabelField GetPhotofileName = new LabelField("",LabelField.FOCUSABLE){
        protected boolean navigationClick(int status, int time){
            Dialog.alert("Clicked");
            return true;
        }
    };

    public static boolean SdcardAvailabulity() {
        String root = null;
        Enumeration e = FileSystemRegistry.listRoots();
        while (e.hasMoreElements()) {
            root = (String) e.nextElement();
            if( root.equalsIgnoreCase("sdcard/") ) {
            }else if( root.equalsIgnoreCase("store/") ) {
            }
        }

        class MySDListener implements FileSystemListener {
            public void rootChanged(int state, String rootName) {
                if( state == ROOT_ADDED ) {
                    if( rootName.equalsIgnoreCase("sdcard/") ) {
                    }
                } else if( state == ROOT_REMOVED ) {
                }
            }
        }

        return true;
    }

    protected boolean invokeAction(int action){
        boolean handled = super.invokeAction(action);
        if(SdcardAvailabulity()){
            PATH = System.getProperty("fileconn.dir.memorycard.photos")+"Image_"+System.currentTimeMillis()+".jpg";//here "str" having the current Date and Time;
        } else {
            // PATH = System.getProperty("file:///store/home/user/pictures/")+"Image_"+System.currentTimeMillis()+".jpg";
            PATH = System.getProperty("fileconn.dir.photos")+"Image_"+System.currentTimeMillis()+".jpg";
        }

        if(!handled){
            if(action == ACTION_INVOKE){
                try{
                    byte[] rawImage = _videoControl.getSnapshot(null);
                    System.out.println("----------1");
                    fileconn=(FileConnection)Connector.open(PATH);
                    System.out.println("----------2");
                    if(fileconn.exists()){
                        fileconn.delete();
                        System.out.println("----------3");
                    }
                    fileconn.create();
                    System.out.println("----------4");
                    OutputStream os=fileconn.openOutputStream();
                    System.out.println("----------5");
                    os.write(rawImage);
                    GetfileName =fileconn.getName();
                    System.out.println("----------6");
                    System.out.println("GetfileName----------"+GetfileName);
                    fileconn.close();
                    System.out.println("----------7");
                    os.close();
                    Status.show("Image is Captured",200);
                    GetPhotofileName.setText(GetfileName);
                    System.out.println("----------8");
                    if(_p!=null)
                        _p.close();
                    System.out.println("----------9");
                }catch(Exception e){
                    if(_p!=null){
                        _p.close();
                    }
                    if(fileconn!=null){
                        try{
                            fileconn.close();
                        }catch (IOException e1){
                            //if the action is other than click the trackwheel(means go to the menu options) then we do nothing;
                        }
                    }
                }
            }
        }
        return handled;
    }

    public MyScreen(){
        setTitle("Camera App");
        try{
            System.out.println("Debug------------10");
            _p = javax.microedition.media.Manager.createPlayer("capture://video?encoding=jpeg&width=1024&height=768");
            _p.realize();
            _videoControl = (VideoControl) _p.getControl("VideoControl");
            System.out.println("Debug------------11");
            if (_videoControl != null){
                Field videoField = (Field) _videoControl.initDisplayMode (VideoControl.USE_GUI_PRIMITIVE, "net.rim.device.api.ui.Field");
                _videoControl.setDisplayFullScreen(true);
                System.out.println("Debug------------12");
                _videoControl.setVisible(true);
                _p.start();
                System.out.println("Debug------------13");
                if(videoField != null){
                    add(videoField);
                    System.out.println("Debug------------14");
                }
            }
        }catch(Exception e){
            if(_p!=null) {
                _p.close();
            }
            Dialog.alert(e.toString());
        }
        add(GetPhotofileName);
    }
}  

在8520(有存儲卡)上,代碼在9780(無存儲卡)上可以正常工作,代碼停在“ System.out.println(“ debug --- 1”)“,有人可以告訴我是否您可以看到我的代碼有任何問題嗎???

  public static boolean SdcardAvailabulity() {
     String root = null;
     Enumeration e = FileSystemRegistry.listRoots();
     while (e.hasMoreElements()) {
         root = (String) e.nextElement();
         if( root.equalsIgnoreCase("sdcard/") ) {
             return true;
         }else if( root.equalsIgnoreCase("store/") ) {
             return false;
         }
     }
     class MySDListener implements FileSystemListener {
         public void rootChanged(int state, String rootName) {
             if( state == ROOT_ADDED ) {
                 if( rootName.equalsIgnoreCase("sdcard/") ) {
                 }
             } else if( state == ROOT_REMOVED ) {
             }
         }
     }
     return true;
}

這是解決方法,我的“ SD卡可用性”代碼僅返回true,這導致在黑莓機未插入存儲卡時無法保存圖片。 @ Eugen Martynov請仔細閱讀代碼,您會發現它在那里:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM