Java
#036 게시물 개수 제한 해제
Ahn_Bo
2020. 12. 10. 11:14
maxArticleCount 없애버리고 아래 코드 추가
private boolean isArticlesFull() {
return articlesSize == articles.length;
}
private int add(String title, String body) {
if (isArticlesFull()) {
System.out.printf(" * 게시글 공간이 추가됩니다!(%d에서 %d로 증가완료) *\n", articles.length, articles.length * 2);
Article[] newArticles = new Article[articles.length * 2];
for (int i = 0; i < articles.length; i++) {
newArticles[i] = articles[i];
}
articles = newArticles;
}
Article article = new Article();
article.id = lastArticleId + 1;
article.title = title;
article.body = body;
articles[articlesSize] = article;
articlesSize++;
lastArticleId = article.id;
return article.id;
}
>오류 해결
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
at Test/Daily.App.add(App.java:51)
at Test/Daily.App.run(App.java:106)
at Test/Daily.Class.main(Class.java:5)
*전체적인 일상은 노션을 통해 작성하고 있습니다.