Updated by Andrey Kamaev almost 13 years ago

I am using OpenCV4Android, I tried the following:

<pre><code class="java"> <pre>
MatOfPoint2f mObjPoints = new MatOfPoint2f();
mObjPoints.fromList(currentObjectPoints); //currentObjectPoints is an ArrayList<Point> - not empty
</code></pre> </pre>

Error:

<pre>
04-16 11:22:58.129: E/AndroidRuntime(32280): FATAL EXCEPTION: Thread-9
04-16 11:22:58.129: E/AndroidRuntime(32280): java.lang.NullPointerException
04-16 11:22:58.129: E/AndroidRuntime(32280): at java.util.ArrayList.toArray(ArrayList.java:518)
04-16 11:22:58.129: E/AndroidRuntime(32280): at org.opencv.core.MatOfPoint2f.fromList(MatOfPoint2f.java:66)
04-16 11:22:58.129: E/AndroidRuntime(32280): at [myclass](Sample1View.java:648)
04-16 11:22:58.129: E/AndroidRuntime(32280): at [mypackadge].processFrame(Sample1View.java:183)
04-16 11:22:58.129: E/AndroidRuntime(32280): at [mypackadge].SampleViewBase.run(SampleViewBase.java:182)
04-16 11:22:58.129: E/AndroidRuntime(32280): at java.lang.Thread.run(Thread.java:1096)
</pre>

Upon inspect method that gives this error:

<pre><code class="java"> <pre>
file: MatOfPoint2f.java

public void fromList(List<Point> lp) {
Point ap[] = lp.toArray(null);
fromArray(ap);
}
</code></pre> </pre>

Somehow the problem is with that toArray(null), i think.
I would say this is probably java version dependent, so here is my version:

<pre>
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK Server VM (build 19.0-b09, mixed mode)
</pre>

I did the following work around that seems to work, i created a local fromList instead of the OpenCV one:

<pre><code class="java"> <pre>
private MatOfPoint2f hackFromList(List<Point> lp) {
Point ap[] = lp.toArray(new Point[0]); // the only difference is here

MatOfPoint2f tmpMat = new MatOfPoint2f();
tmpMat.fromArray(ap);

return tmpMat;
}
</code></pre> </pre>

Back