在我的class类中,我有这个参数构造函数:
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我想在Main中实例化卡带类的几个对象,以测试我的任务中的一些函数。为了我的一生,我无法在没有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谢谢你帮忙!
发布于 2014-02-08 01:04:08
在Cassette构造函数中,您希望:
cass_Emprunteur = nbEmp;而不是行:
for(int i=0;i<nbEmp.length;i++){this.cass_Emprunteur[i] = nbEmp[i];}或者,您还需要在for循环中使用int[]之前初始化它。
发布于 2014-02-08 01:01:03
查看构造函数"this.cass_Emprunteur“为null,然后尝试使用this.cass_Emprunteuri访问
https://stackoverflow.com/questions/21640444
复制相似问题