Question

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.

Was it helpful?

Solution 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.

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top