编码:
//takes in the parameters by int and string and builds an array
public void setParameter(int newParameterNum, String newParameterName) {
this.parameterNum = newParameterNum;
this.parameterName = newParameterName;
this.parameterList = new String[numParameters];
this.parameterList[parameterNum] = parameterName;
for (int i = 0; i < numParameters; i++) {
this.countParameter += i;
}
}
主要代码(不可编辑):
//Add the needed parameters, Report should make sure I am not trying to break it
report1.setParameter(0, "01/01/1970");
report1.setParameter(1, "01/01/2018");
report1.setParameter(2, "pjdt");
错误:
run: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at
week6project.Report.setParameter(Report.java:134) at week6project.Week6Project.main(Week6Project.java:34) C:\Users\nicho\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml: 53:Java 返回:1 BUILD FAILED(总时间:0 秒)
那么,如何忽略我不想添加到数组中的参数?如果请求的参数数量少于传递的参数。
即它要求2 parameters但3在这种情况下通过。
The numParameters is updated through this method:
public void setNumParameters(int newNumParameters) {
this.numParameters = newNumParameters;
}
设置的主要方法:
//Set the number of parameters for each report
report1.setNumParameters(2);
report2.setNumParameters(4);
BIG阳
相关分类