There is an ArrayList “allVariables” that contain an array of integers. I need to find if this array contains the number 1. If it does, the answer should be false, otherwise true.
I wrote some code, but it results in java.lang.NullPointerException:
private boolean notIncluded(int ind, ArrayList<Color> c) {
ArrayList<Integer[]> allVariables = new ArrayList<Integer[]>();
// Filling the ArryList
for (int k = 0; k < c.size(); k++) {
allVariables.add(c.get(k).getColor()); // returns Integer[]
}
if (Arrays.asList(allVariables).contains(1)) {
return false;
}
return true;
}
You need to check for nulls in your code. The following piece of code attempts implementation of what you need and checks for nulls in the process: