Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: What's wrong with my code? (NullPointerException, outOfBoundException)

  1. #1
    Junior Member
    Join Date
    Jan 2022
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Exclamation What's wrong with my code? (NullPointerException, outOfBoundException)

    Hello,
    I have been spending many hours on my school project and there are still exceptions that pop up. Unfortunately I am have yet to understand why all of this happen and I can't find the mistakes I made. I would be very grateful if someone could help me :).
    The exceptions that I can't solve are:NullPointerException, outOfBoundException and from the ligne 51, the array dictionnairetemp doesn't get filled.

    package stringPrograms;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.Normalizer;
    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Scrabble {
    	public static void main(String[] args) throws IOException {
    		Scanner Lire=new Scanner(System.in);
    		int a, b, w, j, k, i, score_Antoine, score_mamie;
    		score_Antoine=score_mamie=a=0;
    		String[][] dictionnaire = new String[30000][29];
    		String[][] dictionnairetemp = new String[30000][29];
    		BufferedReader Lecteur=new BufferedReader(new FileReader("C:\\Users\\GWENDOLINE\\Documents\\STH S1\\Informatique\\Projet\\dictionnaire.txt"));
    		// lire chaque mot du dictionnaire et s'il a 7 lettres ou moins, le mettre dans un tableau de chaine de caractère
    		for(String mot = Lecteur.readLine(); mot != null; mot = Lecteur.readLine()) {
    			if (mot.length()<=7) {
    				dictionnaire[a][0]=mot;
    				dictionnaire[a][1]=" "+ mot.length();
    				a=a+1;
    			}
    		}
    		// Remplir la colonne 2 avec le nombre de a dans chaque mot puis la colonne 3 avec le nombre de b jusqu'à la colonne 28 avec le nombre de z
    		compter(dictionnaire);
    		//saisie des lettres
    		System.out.println("une fois la partie finie, entrez zzzzzzz");	
    		System.out.println("Saisissez vos lettres");
    		String lettres = "";
    		lettres=Lire.next();
    		while (lettres!="zzzzzzz") {
    			System.out.println("vous avez écrit "+lettres);
    			// contrôle de saisie
    			if(lettres.length()>7) {
    				System.out.println("Le nombre de lettres n'est pas conforme, saisissez vos lettres correctement");
    				lettres=Lire.next();
    			}
    			int x=w=0;
    			String[][] motspossibles = new String[200][2];
    			String[][] tablettre= new String[1][29];
    			tablettre[0][0]=lettres;
    			tablettre[0][1]=" "+lettres.length();
    			compter(tablettre);
    			//contrainte de nombre de lettre
    			b=i=0;
    			System.out.println("Si vous voulez une longueur de mots particulière, saisissez-là, sinon saisissez 0");
    			int nombre=Lire.nextInt();
    			if (nombre==0) {
    				dictionnairetemp= Arrays.copyOf(dictionnaire, dictionnaire.length);
    			}else {
    				while (dictionnaire[i][0]!=null && i<a) {
    					if(dictionnaire[i][0].length()==nombre) {
    						for(j=0;j<=27;j++) {
    							dictionnairetemp[b][j]=dictionnaire[i][j];
    							b++;
    						}
    					}
    					i++;
    				}
    			}
    			//Autre contrainte
    			System.out.println("Donnez le nombre de contrainte");
    			int nbcontrainte=Lire.nextInt();
    			String[][] dictionnairecontrainte = new String[20000][29];
    			int r=0;
     
    			if(nbcontrainte==0){
    				// remplir un tableau avec comme première colonne les mots possibles avec les lettres données
    				for(i=0;i<dictionnairetemp.length;i++) {
    					w=0;
     
    					for(j=2;j<=27;j++) {
    						if(tablettre[0][j].compareTo(dictionnairetemp[i][j])>=0){
    							w++;
    						}
    					}
     
    					if (w==26) {
    						motspossibles[x][1]=dictionnairetemp[i][0];
    						x++;
    					}
    				}
    			}else {
    				//créer un nouveau dictionnaire qui prend en compte les contraintes
    				for (k=0;k<nbcontrainte;k++) {
    					System.out.println("saisissez la position puis la lettre voulue en minuscule");
    					int position=Lire.nextInt();
    					String str=Lire.next();
    					char lettrevoulue=str.charAt(0);
    					char [] dictionnairetab = new char [7];
    					r=0;
    					for(i=0;i<a;i++) {
    						String sansmaj=dictionnairetemp[i][0].toLowerCase();
    						sansmaj = Normalizer.normalize(sansmaj, Normalizer.Form.NFD);
    						dictionnairetab=sansmaj.toCharArray();
    						if(dictionnairetab[position-1]==lettrevoulue) {
    							for (j=0;j<=27;j++) {
    								dictionnairecontrainte[r][j]=dictionnairetemp[i][j];
    							}
    							int colonne = (int) lettrevoulue;
    							dictionnairecontrainte[r][colonne-95]=" "+1;
    							r++;
    						}
    					}
    				}
    				for(i=0;i<r;i++) {
    					w=0;
    					for(j=2;j<=27;j++) {
    						if(tablettre[0][j].compareTo(dictionnairecontrainte[i][j])>=0){
    							w++;
    						}
    					}			
    					if (w==26) {
    						motspossibles[x][1]=dictionnairecontrainte[i][0];
    						x++;
    					}
    					}
    				}
    			points(motspossibles,x);
     
    			//ranger le tableau motspossibles
    			int pos, val;
    			i=0;
    			String tempmot, temppoint;
    			while (motspossibles[i][1]!=null && i<motspossibles.length ) {
    				tempmot = motspossibles[i][1];
    				temppoint=motspossibles[i][0];
    				val=Integer.parseInt(temppoint);
    				pos=recherche_position(motspossibles,  i, val);
    		        decaler(motspossibles, pos,i);
    		        motspossibles[pos][0]=temppoint;
    		        motspossibles[pos][1]=tempmot;
    		        i++;
    		        }
    			i=0;
    			//Afficher les mots possibles et le nombre de points correspondant
    			System.out.println("les mots possibles sont");
    			while(motspossibles[i][1]!=null) {
    				System.out.println(motspossibles[i][0]+motspossibles[i][1]);
    				i++;
    			}
    			//Simuler les points  que mamie gagne à chaque tour
    			int lower = 2 ;
    			int higher = 70 ; 
    			int random = (int) (Math.random()*(higher-lower)+lower) ;
    			score_mamie = score_mamie + random; 
     
    			i=0;
    			System.out.println(motspossibles[i][0]);
    			int scoreApotentiel=score_Antoine+Integer.parseInt(motspossibles[i][0]);
    			while(scoreApotentiel>1.02*score_mamie) {
    				i++;
    				scoreApotentiel=score_Antoine+Integer.parseInt(motspossibles[i][0]);
    			}
    			System.out.println("les mots que vous pouvez utiliser sont :");
    			while(scoreApotentiel>score_mamie) {
    				System.out.println(motspossibles[i][1]+" "+motspossibles[i][0]);
    				i++;
    				scoreApotentiel=score_Antoine+Integer.parseInt(motspossibles[i][0]);
    			}
    			System.out.println("le score de mamie est"+score_mamie);
    			System.out.println("Veuillez entrer le nombre de points correspondant au mot que vous avez choisi");
    			int choix=Lire.nextInt();
    			score_Antoine=score_Antoine+choix;
    			System.out.println("Votre score d'Antoine est"+score_Antoine);
    			System.out.println("Saisissez vos lettres");
    			lettres=Lire.next();
    		}
    		System.out.println("La partie est finie");
    	}
     
     
     
    	public static void compter (String [][] T) {
    		char lettre='a';
    		int g=0, k, j, i;
    		int a=T.length;
    		for (j=0;j<a;j++) {
    			if (T[j][0]==null){
    			}else {
    				String minusculemot= T[j][0].toLowerCase();
    				minusculemot = Normalizer.normalize(minusculemot, Normalizer.Form.NFD);
    				char []tabmot= minusculemot.toCharArray();
    				for (k=2;k<28;k++) {	
    					for (i=0;i<tabmot.length;i++) {
    						if(tabmot[i]==lettre) {
    							g++;
    						}
    					}
    					T[j][k]=" "+ g;
    					g=0;
    					lettre++;
    				}	
    				lettre='a';
    			}
    		}
    	}
    	public static void points (String [][] T,int x) {
    		char [] motspossibletab = new char [7];
    		for(int i=0;i<x;i++) {
    			String sansmaj=T[i][1].toLowerCase();
    			sansmaj = Normalizer.normalize(sansmaj, Normalizer.Form.NFD);
    			motspossibletab=sansmaj.toCharArray();
    			int points=0;
    			for (int j=0;j<=(T[i][1].length()-1);j++) {
    				if (motspossibletab[j]=='a' || motspossibletab[j]=='e' || motspossibletab[j]=='i' || motspossibletab[j]=='n' || motspossibletab[j]=='o' || motspossibletab[j]=='r' || motspossibletab[j]=='s' || motspossibletab[j]=='t' || motspossibletab[j]=='u' || motspossibletab[j]=='l') {
    					points++;
    				}
    				if(motspossibletab[j]=='d' || motspossibletab[j]=='m' || motspossibletab[j]=='g') {
    					points=points+2;
    				}
    				if(motspossibletab[j]=='b' || motspossibletab[j]=='c' || motspossibletab[j]=='p') {
    					points=points+3;
    				}
    				if(motspossibletab[j]=='f' || motspossibletab[j]=='h' || motspossibletab[j]=='v') {
    					points=points+4;
    				}
    				if(motspossibletab[j]=='j' || motspossibletab[j]=='q') {
    					points=points+8;
    				}
    				if (motspossibletab[j]=='k' || motspossibletab[j]=='w' || motspossibletab[j]=='x' || motspossibletab[j]=='y' || motspossibletab[j]=='z') {
    					points=points+10;
    				}
    			}
    			T[i][0]=Integer.toString(points);
    		}
    	}
    	public static void afficher (String T[][]) {
    		int i=0;
    		while (T[i][0]!=null && i<=T.length){
    			for (int j=0;j<27;j++) {
    				System.out.print(T[i][j]);
    			}
    		System.out.println(" ");
    		i=i+1;
    		}
    }
    	public static void decaler(String[][] T, int pos1, int pos2){
     
    	    for(int i=pos2-1;i>=pos1;i--){
    	    	T[i+1][0]=T[i][0];
    	    	T[i+1][1]=T[i][1];
    	    }
     
    }
     
     
    	 public static int recherche_position(String [][] T, int pos, int val){
    	    int i=0;
    	    int n;
    	    n=Integer.parseInt(T[i][0]);
    	    while(n<val && i<=pos){
    	    i++;
    	    n=Integer.parseInt(T[i][0]);
    	    }
    	    return (i);
    	    }		
    	}

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    Can you copy the full text of the error messages and paste them here so I can see where the errors are located.
    Also please mark line 51 with a comment so it can easily be found.


    Also please post the input that the user needs to give to the program.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2022
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    Quote Originally Posted by Norm View Post
    Can you copy the full text of the error messages and paste them here so I can see where the errors are located.
    Also please mark line 51 with a comment so it can easily be found.


    Also please post the input that the user needs to give to the program.
    the goal of this program is to show every word that you can make with 7 or less letters. The user needs to give 1)a batch of letters 2)the number of letters of result words 3)the number of constraint (for exemple 1st letter is b) 4)the position where they want a certain letter 5)the letter in question

    I have this exception when 2)!=0 : Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 30000 out of bounds for length 30000
    at stringPrograms.Scrabble.main(Scrabble.java:55)

    when 2) and 3) =0:
    Exception in thread "main" java.lang.NullPointerException: Cannot read field "value" because "anotherString" is null
    at java.base/java.lang.String.compareTo(String.java:2012)
    at stringPrograms.Scrabble.main(Scrabble.java:74)

    and when 2)!=0, nothing is printed after ("les mots possibles sont")

    How do I mark some lines with a comment?
    Last edited by YumiD; January 7th, 2022 at 06:24 AM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    java.lang.ArrayIndexOutOfBoundsException: Index 30000 out of bounds for length 30000
    The maximum index for an array is the the array length minus 1.
    For example: the valid indexes for an array with 3 elements are: 0,1,2
    Make sure the index stops at the length-1.

    java.lang.NullPointerException: Cannot read field "value" because "anotherString" is null
    The elements in arrays of objects are initially set to null when declared. If the element is not given a value, it will be null.
    The code needs to check that the value is not null before using it.


    How do I mark some lines with a comment?
    Add this at the end of a line: // some comment


    user needs to give
    Please post the contents of the command window showing what the user has entered so that they can be copied into the program for testing.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    YumiD (January 7th, 2022)

  6. #5
    Junior Member
    Join Date
    Jan 2022
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    package stringPrograms;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.Normalizer;
    import java.util.Arrays;
    import java.util.Scanner;
     
    public class Scrabble {
    public static void main(String[] args) throws IOException {
    Scanner Lire=new Scanner(System.in);
    int a, b, w, j, k, i, score_Antoine, score_mamie;
    score_Antoine=score_mamie=a=0;
    String[][] dictionnaire = new String[30000][29];
    String[][] dictionnairetemp = new String[30000][29];
    BufferedReader Lecteur=new BufferedReader(new FileReader("C:\\Users\\GWENDOLINE\\Documents\\STH S1\\Informatique\\Projet\\dictionnaire.txt"));
    // lire chaque mot du dictionnaire et s'il a 7 lettres ou moins, le mettre dans un tableau de chaine de caractère
    for(String mot = Lecteur.readLine(); mot != null; mot = Lecteur.readLine()) {
    if (mot.length()<=7) {
    dictionnaire[a][0]=mot;
    dictionnaire[a][1]=" "+ mot.length();
    a=a+1;
    }
    }
    // Remplir la colonne 2 avec le nombre de a dans chaque mot puis la colonne 3 avec le nombre de b jusqu'à la colonne 28 avec le nombre de z
    compter(dictionnaire);
    //saisie des lettres
    System.out.println("une fois la partie finie, entrez zzzzzzz");
    System.out.println("Saisissez vos lettres");
    String lettres = "";
    lettres=Lire.next();
    while (lettres!="zzzzzzz") {
    System.out.println("vous avez écrit "+lettres);
    // contrôle de saisie
    if(lettres.length()>7) {
    System.out.println("Le nombre de lettres n'est pas conforme, saisissez vos lettres correctement");
    lettres=Lire.next();
    }
    int x=w=0;
    String[][] motspossibles = new String[200][2];
    String[][] tablettre= new String[1][29];
    tablettre[0][0]=lettres;
    tablettre[0][1]=" "+lettres.length();
    compter(tablettre);
    //contrainte de nombre de lettre
    b=i=0;
    System.out.println("Si vous voulez une longueur de mots particulière, saisissez-là, sinon saisissez 0");
    int nombre=Lire.nextInt();
    if (nombre==0) {
    dictionnairetemp= Arrays.copyOf(dictionnaire, dictionnaire.length);
    }else {
    while (dictionnaire[i][0]!=null && i<a) {
    if(dictionnaire[i][0].length()==nombre) {
    for(j=0;j<=27;j++) {
    dictionnairetemp[b][j]=dictionnaire[i][j]; //line 55
    b++;
    }
    }
    i++;
    }
    }
    //Autre contrainte
    System.out.println("Donnez le nombre de contrainte");
    int nbcontrainte=Lire.nextInt();
    String[][] dictionnairecontrainte = new String[20000][29];
    int r=0;
     
    if(nbcontrainte==0){
    // remplir un tableau avec comme première colonne les mots possibles avec les lettres données
    for(i=0;i<dictionnairetemp.length;i++) {
    w=0;
     
    for(j=2;j<=27;j++) {
    if(tablettre[0][j].compareTo(dictionnairetemp[i][j])>=0){ //line 74
    w++;
    }
    }
     
    if (w==26) {
    motspossibles[x][1]=dictionnairetemp[i][0];
    x++;
    }
    }
    }else {
    //créer un nouveau dictionnaire qui prend en compte les contraintes
    for (k=0;k<nbcontrainte;k++) {
    System.out.println("saisissez la position puis la lettre voulue en minuscule");
    int position=Lire.nextInt();
    String str=Lire.next();
    char lettrevoulue=str.charAt(0);
    char [] dictionnairetab = new char [7];
    r=0;
    for(i=0;i<a;i++) {
    String sansmaj=dictionnairetemp[i][0].toLowerCase();
    sansmaj = Normalizer.normalize(sansmaj, Normalizer.Form.NFD);
    dictionnairetab=sansmaj.toCharArray();
    if(dictionnairetab[position-1]==lettrevoulue) {
    for (j=0;j<=27;j++) {
    dictionnairecontrainte[r][j]=dictionnairetemp[i][j];
    }
    int colonne = (int) lettrevoulue;
    dictionnairecontrainte[r][colonne-95]=" "+1;
    r++;
    }
    }
    }
    for(i=0;i<r;i++) {
    w=0;
    for(j=2;j<=27;j++) {
    if(tablettre[0][j].compareTo(dictionnairecontrainte[i][j])>=0){
    w++;
    }
    }
    if (w==26) {
    motspossibles[x][1]=dictionnairecontrainte[i][0];
    x++;
    }
    }
    }
    points(motspossibles,x);
     
    //ranger le tableau motspossibles
    int pos, val;
    i=0;
    String tempmot, temppoint;
    while (motspossibles[i][1]!=null && i<motspossibles.length ) {
    tempmot = motspossibles[i][1];
    temppoint=motspossibles[i][0];
    val=Integer.parseInt(temppoint);
    pos=recherche_position(motspossibles, i, val);
    decaler(motspossibles, pos,i);
    motspossibles[pos][0]=temppoint;
    motspossibles[pos][1]=tempmot;
    i++;
    }
    i=0;
    //Afficher les mots possibles et le nombre de points correspondant
    System.out.println("les mots possibles sont");
    while(motspossibles[i][1]!=null) {
    System.out.println(motspossibles[i][0]+motspossibles[i][1]);
    i++;
    }
    /*//Simuler les points que mamie gagne à chaque tour
    int lower = 2 ;
    int higher = 70 ;
    int random = (int) (Math.random()*(higher-lower)+lower) ;
    score_mamie = score_mamie + random;
     
    i=0;
    System.out.println(motspossibles[i][0]);
    int scoreApotentiel=score_Antoine+Integer.parseInt(mot spossibles[i][0]);
    while(scoreApotentiel>1.02*score_mamie) {
    i++;
    scoreApotentiel=score_Antoine+Integer.parseInt(mot spossibles[i][0]);
    }
    System.out.println("les mots que vous pouvez utiliser sont :");
    while(scoreApotentiel>score_mamie) {
    System.out.println(motspossibles[i][1]+" "+motspossibles[i][0]);
    i++;
    scoreApotentiel=score_Antoine+Integer.parseInt(mot spossibles[i][0]);
    }
    System.out.println("le score de mamie est"+score_mamie);
    System.out.println("Veuillez entrer le nombre de points correspondant au mot que vous avez choisi");
    int choix=Lire.nextInt();
    score_Antoine=score_Antoine+choix;
    System.out.println("Votre score d'Antoine est"+score_Antoine);*/
    System.out.println("Saisissez vos lettres");
    lettres=Lire.next();
    }
    System.out.println("La partie est finie");
    }
     
     
     
    public static void compter (String [][] T) {
    char lettre='a';
    int g=0, k, j, i;
    int a=T.length;
    for (j=0;j<a;j++) {
    if (T[j][0]==null){
    }else {
    String minusculemot= T[j][0].toLowerCase();
    minusculemot = Normalizer.normalize(minusculemot, Normalizer.Form.NFD);
    char []tabmot= minusculemot.toCharArray();
    for (k=2;k<28;k++) {
    for (i=0;i<tabmot.length;i++) {
    if(tabmot[i]==lettre) {
    g++;
    }
    }
    T[j][k]=" "+ g;
    g=0;
    lettre++;
    }
    lettre='a';
    }
    }
    }
    public static void points (String [][] T,int x) {
    char [] motspossibletab = new char [7];
    for(int i=0;i<x;i++) {
    String sansmaj=T[i][1].toLowerCase();
    sansmaj = Normalizer.normalize(sansmaj, Normalizer.Form.NFD);
    motspossibletab=sansmaj.toCharArray();
    int points=0;
    for (int j=0;j<=(T[i][1].length()-1);j++) {
    if (motspossibletab[j]=='a' || motspossibletab[j]=='e' || motspossibletab[j]=='i' || motspossibletab[j]=='n' || motspossibletab[j]=='o' || motspossibletab[j]=='r' || motspossibletab[j]=='s' || motspossibletab[j]=='t' || motspossibletab[j]=='u' || motspossibletab[j]=='l') {
    points++;
    }
    if(motspossibletab[j]=='d' || motspossibletab[j]=='m' || motspossibletab[j]=='g') {
    points=points+2;
    }
    if(motspossibletab[j]=='b' || motspossibletab[j]=='c' || motspossibletab[j]=='p') {
    points=points+3;
    }
    if(motspossibletab[j]=='f' || motspossibletab[j]=='h' || motspossibletab[j]=='v') {
    points=points+4;
    }
    if(motspossibletab[j]=='j' || motspossibletab[j]=='q') {
    points=points+8;
    }
    if (motspossibletab[j]=='k' || motspossibletab[j]=='w' || motspossibletab[j]=='x' || motspossibletab[j]=='y' || motspossibletab[j]=='z') {
    points=points+10;
    }
    }
    T[i][0]=Integer.toString(points);
    }
    }
    public static void afficher (String T[][]) {
    int i=0;
    while (T[i][0]!=null && i<=T.length){
    for (int j=0;j<27;j++) {
    System.out.print(T[i][j]);
    }
    System.out.println(" ");
    i=i+1;
    }
    }
    public static void decaler(String[][] T, int pos1, int pos2){
     
    for(int i=pos2-1;i>=pos1;i--){
    T[i+1][0]=T[i][0];
    T[i+1][1]=T[i][1];
    }
     
    }
     
     
    public static int recherche_position(String [][] T, int pos, int val){
    int i=0;
    int n;
    n=Integer.parseInt(T[i][0]);
    while(n<val && i<=pos){
    i++;
    n=Integer.parseInt(T[i][0]);
    }
    return (i);
    }
     
    }


    --- Update ---

    First senario:
    une fois la partie finie, entrez zzzzzzz
    Saisissez vos lettres
    basile
    vous avez écrit basile
    Si vous voulez une longueur de mots particulière, saisissez-là, sinon saisissez 0
    5
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 30000 out of bounds for length 30000
    at stringPrograms.Scrabble.main(Scrabble.java:55)

    second senario
    une fois la partie finie, entrez zzzzzzz
    Saisissez vos lettres
    basile
    vous avez écrit basile
    Si vous voulez une longueur de mots particulière, saisissez-là, sinon saisissez 0
    0
    Donnez le nombre de contrainte
    0
    Exception in thread "main" java.lang.NullPointerException: Cannot read field "value" because "anotherString" is null
    at java.base/java.lang.String.compareTo(String.java:2012)
    at stringPrograms.Scrabble.main(Scrabble.java:74)

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    .ArrayIndexOutOfBoundsException: Index 30000 out of bounds for length 30000
    What variable has the 30000 value? That value is too large for the array. The max allowed index is 30000-1
    The code needs to test that variable for being past the end of the array. Its value needs to be less than 30000.

    java.lang.NullPointerException: Cannot read field "value" because "anotherString" is null
    What variable has the null value? Why doesn't it have a valid value?
    Check the code to see why that variable does not have a valid value.
    If you don't understand my answer, don't ignore it, ask a question.

  8. The Following User Says Thank You to Norm For This Useful Post:

    YumiD (January 7th, 2022)

  9. #7
    Junior Member
    Join Date
    Jan 2022
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code? (NullPointerException, outOfBoundException)

    Thank you, I was able to solve it!

Similar Threads

  1. How to fix error java.lang.NullPointerException in this code?
    By elf01b in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 15th, 2020, 12:40 PM
  2. what's wrong with this code ?? HELP
    By Roosh in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 14th, 2014, 10:35 AM
  3. NullPointerException Error in Code that Prints Array Elements
    By Atypically Engineered in forum Collections and Generics
    Replies: 8
    Last Post: April 6th, 2012, 10:21 PM
  4. [SOLVED] nullPointerException, but doesn't look wrong to me
    By Goldfinch in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 17th, 2012, 05:26 PM
  5. Replies: 3
    Last Post: October 19th, 2011, 11:55 PM