728x90

코드를 구현하다보니 파싱처리를 하는데 동일한 단어가 들어간 곳이 다른 곳에도 존재하는 걸 몰랐다.

파싱할 내용이 다르다보니 에러가 발생했다.


해결법은

try {
    int stlocation = str.indexOf("GW=");
    int endlocation = str.length();
    String temp = str.substring(stlocation + 4, endlocation).trim();
    String[] part = temp.split("\\s{1,}"); // 공백 단위로 메시지를 분리하라.
    if (part[3].length() > 4) {
        ipaddr = part[3];
    }
} catch(IndexOutOfBoundsException e) {
    System.out.println(e);
}


와 같이 try catch 문으로 해결했다.



블로그 이미지

Link2Me

,