初始化对象在访问方法时会导致NPE

时间:2015-03-24 13:35:39

标签: java

在下面的代码中我试着用带有Java API的opeCV lib打开AVI视频。 在运行时,我在代码中提到下面提到的NPE。

为什么那条线会导致NPE?

public class PlayVideo {

VideoCapture vCapture;

public static void main(String[] args) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    VideoCapture vCapture = new VideoCapture("C:/private/..../AVIs/parabole.avi");
    boolean mediaOpened = vCapture.open("C:/private/..../AVIs/parabole.avi");

    if (!mediaOpened) {
        System.out.println("media failed to open");
    } else {
        List<Size> prevSizes = vCapture.getSupportedPreviewSizes();//causes NPE

        for (Size s: prevSizes) {
            System.out.println("supportedSize: " + s);
        }

    }
}

堆栈跟踪

Exception in thread "main" java.lang.NullPointerException
at org.opencv.highgui.VideoCapture.getSupportedPreviewSizes(VideoCapture.java:492)
at openCVJavaExamples.PlayVideo.main(PlayVideo.java:22)

0 个答案:

没有答案