【发布时间】:2014-01-12 17:25:28
【问题描述】:
我试图找出我的代码发生了什么,我不断收到 nullexeptionpointer 问题。所以我决定减少我的代码并找出发生了什么。我想删除提供要删除的索引的特定元素,然后移动它后面的所有元素以填充剩余的空间。
移动所有元素后,我想将数组中的最后一个元素设置为空,但我得到错误并且无法编译。
public static void main(String[] args) {
int [] charSort = new int[] {12, 5, 7, 4 ,26 ,20 ,1, 6 ,3 ,14, 8, 11};
TextIO.putln("ArrayNum = [12, 5, 7, 4 ,26 ,20 ,1, 6 ,3 ,14, 8, 11]\n");
TextIO.put("Sorted ArrayNum is: \n");
//IntSelecttionSort(charSort);
TextIO.putln(Arrays.toString(charSort));
TextIO.put("Enter: "); RemoveShift (charSort, TextIO.getInt());
}
public static void RemoveShift (int[] move, int p){
for(int i = 0; i<move.length; i++){
TextIO.put(i+", ");
}
TextIO.putln();
for(int i = p; i<move.length-1; i++){
move[i]=move[i+1];
}
move[move.length-1]=null; // null seems not to work here
TextIO.putln(Arrays.toString(move));
}
【问题讨论】:
标签: java arrays nullpointerexception