如何修复线程 "main" java.lang.NullPointerException 中的异常?
how to fix Exception in thread "main" java.lang.NullPointerException ?
我是 Java 的编程初学者。
我知道有关此特定消息错误的主题数量,但我无法解决此问题。错误指示在以下代码的第 23 行中。
我知道这个问题似乎与 null 引用有关,但我没有看到我的方法 "Recommander" 如何没有为所有引用赋值。
public class 推荐人{
// predetermined array of series
private String[] serie= {"Friends S1","Friends S2",
"Friends S6","Friends S7", "Friends S8", "How I met your mother S1",
"How I met your mother S2","How I met your mother S3 ","Castle S3",
"Santa Clarita Diet S1", "Modern Family S1","Modern Family S2",
"Family Guy S6", "The Simpsons S5"};
// array of the purchases of one customer
private int[] profil ;
//number of profiles in the database
private int nbProfils = 10 ;
// array of all the profiles from the database and the series available
private int[][] records ;
// creation of an instance of the object Recommander
public Recommander() {
for (int k=0;k<=nbProfils-1; k++) {
for (int i=0; i<=serie.length-1;i++) {
records[k][i]= (int) (Math.random())*2 ;
}
}
}
// Display of the series available in store
public String affichageSerie() {
String Affichage = "" ;
for (int i = 0 ; i<=serie.length-1; i++) {
Affichage = Affichage + serie[i] + "\n" ;
}
return Affichage ;
}
}
初始化数组
private int[][] records = new int[nbProfils][serie.length];
我是 Java 的编程初学者。 我知道有关此特定消息错误的主题数量,但我无法解决此问题。错误指示在以下代码的第 23 行中。 我知道这个问题似乎与 null 引用有关,但我没有看到我的方法 "Recommander" 如何没有为所有引用赋值。
public class 推荐人{
// predetermined array of series
private String[] serie= {"Friends S1","Friends S2",
"Friends S6","Friends S7", "Friends S8", "How I met your mother S1",
"How I met your mother S2","How I met your mother S3 ","Castle S3",
"Santa Clarita Diet S1", "Modern Family S1","Modern Family S2",
"Family Guy S6", "The Simpsons S5"};
// array of the purchases of one customer
private int[] profil ;
//number of profiles in the database
private int nbProfils = 10 ;
// array of all the profiles from the database and the series available
private int[][] records ;
// creation of an instance of the object Recommander
public Recommander() {
for (int k=0;k<=nbProfils-1; k++) {
for (int i=0; i<=serie.length-1;i++) {
records[k][i]= (int) (Math.random())*2 ;
}
}
}
// Display of the series available in store
public String affichageSerie() {
String Affichage = "" ;
for (int i = 0 ; i<=serie.length-1; i++) {
Affichage = Affichage + serie[i] + "\n" ;
}
return Affichage ;
}
}
初始化数组
private int[][] records = new int[nbProfils][serie.length];