0

Please i need your help. Very much appreciated I don't know what to do with this error. I am new to [OpenCV] and I hope you will help me solve this.

[3]: Source Code:

Caused by: java.lang.NullPointerException at opencv.OpenCV.start(OpenCV.java:49)

exitButton.setOnAction((ActionEvent event)->{
        System.exit(0);
    });

[Edited]: I try this, the errors gone but no buttons display and no camera frame display:

exitButton = new Button();
exitButton.setOnAction((ActionEvent event)->{
System.exit(0);
});
videoButton = new Button();
videoButton.setOnAction((ActionEvent event)->{

Any suggestions with this code?

Source Code:

 if(!isStart){
                frame.setFitWidth(640);
                frame.setFitWidth(480);
                frame.setPreserveRatio(true);

                capture.open(0);
                capture.set(Videoio.CAP_PROP_FRAME_WIDTH, 640);
                capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 480);

                if (capture.isOpened()){
                    isStart = true;

                    Runnable frameGrabber = new Runnable() {
                        @Override
                        public void run() {
                            Image imageToShow = grabFrame();
                            frame.setImage(imageToShow);
                        }
                    };
                    timer = Executors.newSingleThreadScheduledExecutor();
                    timer.scheduleAtFixedRate(frameGrabber, 0, 33, `TimeUnit.MILLISECONDS);`
                    videoButton.setText("Stop");
                }else {
                    System.err.println("Open Camera Error!");
                } 
            }
            else {
                isStart = false;
                videoButton.setText("Start");
                try{
                    timer.shutdown();
                    timer.awaitTermination(33, TimeUnit.MILLISECONDS);
                }catch(InterruptedException e){
                    System.err.println(e);
                }
                capture.release();
                frame.setImage(null);
            }         
        });
Gamz
  • 1
  • 3
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Slaw May 14 '18 at 08:31
  • Thanks @Slaw but how to do it? it says cannot be null. How about the lambda expression and this java.lang.reflect.InvocationTargetException. Sorry I'm new to Java this errors makes me mad. – Gamz May 14 '18 at 09:56
  • Thanks, @Slaw I already posted the edited **source code**. Thanks for the good advice very much appreciated.. – Gamz May 14 '18 at 11:22

0 Answers0