我是Java編程的初學者。 我知道這個特定郵件錯誤的主題數量,但我無法解決此問題。在下面的代碼中,錯誤被指示在第23行。 我知道這個問題似乎與空引用有關,但我無法看到我的方法「Recommander」是不是將值分配給所有引用。如何解決線程「main」中的異常java.lang.NullPointerException?
公共類Recommander {
// 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 ;
}
}
請出示線,所以我們是不是所有的強制倒計時23線。第23行似乎只是有一個大括號,所以加倍你需要明確顯示該行。 – Carcigenicate
您的記錄變量未初始化,因此它是空引用,當您嘗試在for循環中寫入它時,我認爲它是第23行。您必須使用類似'private int [] [ ] records = new int [nbprofiles] [serie.length];'。 –