Hello, I'm really new to Java. I have to do an exercice where a function compares two String arrays (one randomly generated by the computer and the other chosen by the user. And each time it finds an identical element, it puts it in a third array that's String too. The problem is that the main totally ignore the function and doesn't want to call her. And I got this error message :
(in thread "main" java.lang.NullPointerException
at Mastermind_ho.compareColor(Mastermind_ho.java:80)
at Mastermind_ho.main(Mastermind_ho.java:31))
I did this (I post the main as well as the function in question, to lighten I'm not posting the random function unless it's necessary). Thank you in adavnce
--------------- the main
import java.util.Scanner;
public class Mastermind_ho {
static Scanner sc = new Scanner(System.in);
static String [] TAB_REF_COLORS = {"rouge","jaune","vert","bleu","orange","blanc","v iolet","fuchsia"};
static int NB_COLORS = 4;
static int compteur=0;
static String [] combination;
static String [] tabJoueur;
static String [] tabCorrect= {" "," "," "," "};
public static void main(String[] args) {
String [] combinaisonSecrete = generateRandomCombination();
for(int i=0;i<4;i++) {
System.out.print(combinaisonSecrete[i]+ "|");
}
String [] combinaisonJoueur;
System.out.println();
do {
combinaisonJoueur = choixNumerote();
for(int i=0;i<4;i++) {
System.out.print(combinaisonJoueur[i]+ "|");
}
//??
}while (compteur<=12 && (12-compteur)>0);
compareColor (tabJoueur, combination);
for(int k=0;k<4;k++) {
System.out.print(tabCorrect[k]+ "|");
}
sc.close();
}
--------------- the function
static void compareColor (String [] tabPlayer, String [] tabOrdi) {
int sizeTj = tabPlayer.length;
int sizeTm = tabOrdi.length;
int k=0;
for (int i=0;i<sizeTj;i++) {
for(int j=0; j<sizeTm; j++) {
if (tabOrdi[j]==tabPlayer[i]) {
System.out.print("Vous avez trouver une couleur");
tabCorrect[k]=tabOrdi[j];
k++;
}
else {
continue;
}
}
}