initasync Nullpointer Exception
Hi all,
I have the following question:
I have several ideas for different apps using one and the key feature. Therefore I want to implement that feature as a library project. I created one, referenced the OpenCV Library project and also created a project for Android JUnit test.
In the library project I have a class that extends activity in which call the constructor and initialize opencv in async mode like this:
public class Abc extends Activity implements IAbc {
final String TAG = "Hello World";
private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public Abc(){
super();
Log.i(TAG, "Trying to load OpenCV library");
if (!OpenCVLoader.initDebug()) {
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mOpenCVCallBack);
} else {
Log.d(TAG, "OpenCV library found inside package. Using it!");
mOpenCVCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
So I basically made things like in the examples ( at least I think I did). I now create an instance of Abc class in my Android test. The test starts and fails with a NullPointerException that is being triggered by
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mOpenCVCallBack);
I can follow it back to ContentWrapper.bindService (but can't look at the source code of this method). Whole exception looks like this:
java.lang.NullPointerException
at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:26)
at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:95)
at de.spospiech.gazetracker.Abc.estimateGazeDirection(Starburst.java:54)
at de.spospiech.gazetracker.AbcTest.testStarburst(StarburstTest.java:33)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)
Of course I do have OpenCV Manager 3.0.0 installed on my device. Examples do work fine.
Any idea what I do wrong?
Thanks and greetings, Sebastian