I have an object which has a name, String [] there is also a another String array which just stores the name of the object (The first parameter) which is in main.
import java.util.*;
class Dice{
public String [] side;
public String name;
public Dice (String n, String ... a){
name = n;
side = a;
}
//Setter and Getter name
public String getName(){
return name;
}
public void setName(String n){
name = n;
}
}
The objects parameters are set in the main class.
Dice easy = new Dice("Green:","Brain","Brain","Brain","Foot Print","Foot Print","Shotgun");
The string array just stores the name Easy:
.
I am trying to compare the two arrays by passing them into a method in main.
//Removeing the 3 dice which were picked form the cup of the current player
public static Dice [] cup(Dice [] a , String [] b){
Dice [] currentCup = new Dice[a.length];
for (int i = 0; i < b.length; i++) {
if (b[i] == a[i].getName()) {
currentCup[i].setName("");
}
}
return currentCup;
}
If the name of the object equals the name in the String array the objects name should equal and empty String(" ").
I am getting a error
Exception in thread "main" java.lang.NullPointerException
I understand that an ArrayList is much better to use here as I can just .remove(i, elem). But I do not know how to pass an ArrayList into a constructor.
Also this is just pure practice for myself using arrays.
The result should be that if the Dice [].getName() equals easy the name of that Dice object should be an empty String " ".