gpt4 book ai didi

java - 请帮助我 "java Exception in thread main java.lang.nullpointerexception"

转载 作者:行者123 更新时间:2023-11-29 05:12:58 26 4
gpt4 key购买 nike

<分区>

我想为我的项目寻求帮助。我是一名新手程序员,我没有收到此错误 "exception in thread main java.lang.nullpointerexception"

这是我的代码:

 public class Slumbook{

public String codeName;

public Slumbook(){
//
}

public Slumbook(String codeName){
this.codeName = codeName;
}

public String getCodeName(){return codeName;}

public void setCodeName(String codeName){this.codeName = codeName;}
}

Driver Program代码是:-

import java.util.*;

public class SlumbookD{
public static void main(String[] args){

Scanner sc = new Scanner(System.in);
Slumbook[] slum = new Slumbook[20];

for(int n=0; n<10; n++){
slum[n].setCodeName(sc.nextLine());
}
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com