Obtention de NullPointerException lorsqu 'il tente d'accéder aux pierres [0] .length. S'il vous plaît, aidez. J'ai déjà Initialized Stones Object.exception de pointeur nul en Java.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Solution
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Scanner sc = new Scanner(System.in);
int times = sc.nextInt();
String stones[] = new String[times];
int score = 0;
int counter;
for(int tcase = 0; tcase < times; tcase++)
stones[tcase] = br.readLine();
int s = stones[0].length();
for (int i = 0; i < s ; i++) {
char j = stones[0].charAt(i);
counter = 0;
for (int k = 1; k < times; k++) {
char aa[] = stones[k].toCharArray();
for (int l = 0; l <aa.length ; l++) {
if(aa[l]==j)
{
counter++;
break;
}
}
if (counter==times-1) {
score++;
}
}
}
System.out.println(score);
}
}
Obtenir NullPointerException lorsque je tente d'accéder à des pierres [0] .length(). Aidez-nous
duplication possible de [Qu'est-ce qu'une exception pointeur nul, et comment puis-je résoudre ce problème?] (Http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how -do-i-fix-it) – DavidPostill
Bizarre, j'ai copié ton code, lance-le et je ne reçois aucune exception. Quelle est votre contribution? – libik
c'est en fait un programme de HackerRank. Cela fonctionne correctement quand je le lance dans mon ordinateur portable. Le problème se pose lorsque j'essaie de le soumettre. – Ishada