public class test {
private String title;
private String author;
public test () {}
public test (String title, String author) {
this.title = title;
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public void showInfo() {
System.out.println(title+","+author);
}
}
public class ca {
static public int Count = 0;
public static void main(String[] args) {
test[] library = new test[5];
library[Count].setTitle("tlqkf");
System.out.println(library[0].getTitle());
}
}
test 인스턴스 만들고 ca에서 실행하는데 오류가 뜹니다. Count를 0으로 초기화해도 뜨는데 어떻게 해야할까요?
오류 전체입니다
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "test.setTitle(String)" because "library[ca.Count]" is null at ca.main(ca.java:9)
- dc official App
test를 5개 담는 배열을 만들어놓고 안에 객체를 안집어넣었잖어.... test a=new test("타이틀","작가");해서 배열에 넣고 접근해야지..
아 감사합니다! 드디어 고쳤네요 - dc App
그리구 library면 클래스명을 test가 아니라 book이라구 하던지...리펙터로 리네임하자..
던->든
ㅋㅋ - dc App