我有這樣的構造函數通過參數在我的磁帶類:爪哇 - 與數組實例化一個對象作爲參數
public class Cassette {
private int cass_Num;
private String cass_Titre;
private String cass_Realisat;
private int nbCopie;
private int [] cass_Emprunteur;
//...code
public Cassette(int num, String titre, String real, int copies, int[] nbEmp){
this.cass_Num = num;
this.cass_Titre = titre;
this.cass_Realisat = real;
this.nbCopie = copies;
for(int i=0;i<nbEmp.length;i++){this.cass_Emprunteur[i] = nbEmp[i];}
}
//set methods...
//get methods...
}//end
我想要實例在我的主紙盒類的一些對象來測試某些功能爲我的分配。 我不能爲我的生活,找到合適的方式來做到這一點沒有得到一個null.Pointer.Exception
這些都是在我的主要線路:
//...code
Cassette [] tabCas = new Cassette[MAX_CASSETTES];
for(int i=0;i<tabCas.length;i++){tabCas[i]= new Cassette();}
tabCas[0] = new Cassette(0001,"Jurassic Pork","Steven Swineberg",7,new int[] {11111,44444}); //<--- error here
//...code
感謝您的幫助!
查看異常的堆棧跟蹤,看看哪一行正在拋出它?然後看看該行上的變量如何爲空。 – vanza