I’m working on a project using OpenCV, and there is a function which takes a List as a parameter.
Core.split(Mat m, List<Mat> mv);
I tried looking at documentation for List in Java however I’m confused as to how I would create a new list to use. I saw someone online say that list was just an Interface, but I’m not sure exactly what that means? (Sorry – Java isn’t my first language)
What I was doing was –
private List<Mat> mList;
private Mat listItem1; (etcetera)
mList.add(listItem1)
The first part does not cause an error however when I try to mList.add(listItem1) this causes a NULL pointer exception. I’m assuming this is because I haven’t initialised the List. I thought this would be a case of mList = new List<Mat>(); however this gives me the error “Cannot instantiate the type List < Mat >”
Any help would be much appreciated – thanks! Sorry if this is a silly question.
Listis an interface. You need to use an implementation ofList. TryArrayList.Check the JavaDoc for List for other implementations.
The reason you cannot instantiate
Listis because it is an interface. It provides a contract with which you can be assured that any implementers will have defined all of its methods. This way, you can work on aListreference without needing to know its exact implementation. (that is,ArrayList,LinkedList,Vector, etc…)