ExceptionInInitializerError in Stitcher with JavaCV for Android

僤鯓⒐⒋嵵緔 提交于 2019-12-11 20:31:35

问题


I am using this code for image stitching with JavaCV on Android:

public void ImageStitching() {
    Stitcher stitcher = Stitcher.createDefault(false);
    MatVector images = new MatVector(2);
    images.put(0,cvLoadImage("sample1.png"));
    images.put(1,cvLoadImage("sample2.png"));

    IplImage result = new IplImage(null);
    int status = stitcher.stitch(images,result);

    if( status == Stitcher.OK )
    {
        cvSaveImage("result.png", result);
    }
}

But when I execute it, the app crashes and the log shows the following error:

java.lang.ExceptionInInitializerError at ...

and the error points to the Stitcher initilization, the first line of my code. If I try to do Stitcher stitcher; it doesn't break, but I cannot do anything else since the stitcher is not initialized. If I try to initialize it to null it crashes with the same error.

Any idea about the problem? I have been searching for a while and all the people use that and it seems to work.


回答1:


ExceptionInInitializerError

Signals that an unexpected exception has occurred in a static initializer. An ExceptionInInitializerError is thrown to indicate that an exception occurred during evaluation of a static initializer or the initializer for a static variable.

I would do something like

Stitcher stitcher;
{
    try {
        stitcher = Stitcher.createDefault(false);
    } catch (Throwable t) {
        t.printStackTrace();
        throw t;
    }
}

and see what really happens -- unless you anready have that info in the caused by clause of the exception trace.

PS sometimes errors happen when a class is initialized on the wrong thread (for example, in early versions of Android the AsyncTask class required explicit initialization on the main thread in an application that would otherwise load this class on a worker thread).




回答2:


Ok, I got it.

The problem was that the library opencv_stitching.so was only in the folder armeabi and I needed in the armeabi-v7a one. Not I can declare the stitcher and initialize it.



来源:https://stackoverflow.com/questions/20045041/exceptionininitializererror-in-stitcher-with-javacv-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!