我试图找出我的代码发生了什么,我不断得到nullexeptionpointer问题.所以我决定减少我的代码并找出最新情况.我想删除一个特定的元素,提供要删除的索引,然后移动后面的所有元素以填充剩余的空间.
移动所有元素后,我想将数组中的最后一个元素设置为null,但是我得到错误并且不会编译.
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; // …Run Code Online (Sandbox Code Playgroud) 我尝试在子类Manager中调用超类的super.toString,但它不起作用.我希望输出如下:
current data:
#Person (ID=1):
firstname: NN
lastname: NN
email: unknown
date of birth: 01.01.1970
annual pay: 0.00
#Manager:
annual base pay: 0.00
bonus: 0.00
firstname: lastname: email: date of birth: enter date (y m d)
Run Code Online (Sandbox Code Playgroud)
但我得到的是没有显示超类的属性:
firstname:
lastname:
email:
date of birth: enter date (y m d)
Run Code Online (Sandbox Code Playgroud)
任何建议将受到高度赞赏谢谢
public class Person {
private String fn;
private String ln;
private String email;
private Date dob;
private static int nextID=1;
private final int ID=nextID++;
Person(){
this.fn = "NN";
this.ln = "NN"; …Run Code Online (Sandbox Code Playgroud)