Spring
자바 for문에서 length cannot be resolved or is not a field 해결
soranta
2020. 2. 14. 01:06
for (int j = 0; j < findFollowers.length; j++) {
feedVO.setUserId(findFollowers.getFollowerId());
feedVO.setFolloweeId(userId);
feedVO.setPostId(id);
feedDAO.insertFeed(feedVO);
}
리스트 findFollowers의 데이터 개수만큼 for문을 돌려고 했다.
그래서 ctrl+space 했을 때 나오는 가장 기본 형식인
for (int i = 0; i < array.length; i++) {
}
이 형식을 그대로 사용했다.
그래서 j < findFollowers.length; 된 것 ㅎ
그랬더니 length에 계속 빨간줄이 떴다.
length cannot be resolved or is not a field
findFollowers는 ArrayList이기 때문에 length()가 아닌 size()를 사용해야 한다.
또한 나는 현재 for문을 돌면서 j가 증가해야 하는데 j에 관한 부분도 없어서 추가해주어야 한다.
for (int j = 0; j < findFollowers.size(); j++) {
feedVO.setUserId(findFollowers.get(j).getFollowerId());
feedVO.setFolloweeId(userId);
feedVO.setPostId(id);
feedDAO.insertFeed(feedVO);
}
다음과 같이 수정할 수 있다. 오류 없이 for문이 완성된다.
Length cannot be resolved or is not a field (ArrayList get function)
My code looks like this: private ArrayList Actions; private String Action; Actions.get(Actions.length-1).getString(); I keep getting an error on this last line (length cannot be re...
stackoverflow.com