-5
public static void main(String[] args) throws IOException {
잘 작동에서 실행되는 몇 가지 코드를 가지고, 그러나
public class Locate {
public Locate() throws IOException {
을 읽고 다른 클래스에서 호출 할 다른 클래스 자바에서 클래스를 호출 내가 오류가 알고
Locate location = new Locate();
를 사용
,
Exception in thread "main" java.lang.StackOverflowError
at geolocatenodes.Locate.<init>(Locate.java:26)
at geolocatenodes.Locate.<init>(Locate.java:28)
다른 클래스의 클래스를 호출하는 올바른 방법은 무엇입니까?
많은 감사
편집 :public Locate() throws IOException {
Locate obj = new Locate();
String file = "IP.txt";
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
// System.out.println(line);
ServerLocation location = obj.getLocation(line);
System.out.println(location);
try {
String filename = "Locations.txt";
try (FileWriter fw = new FileWriter(filename, true)) {
fw.write(location + "\n");
}
} catch (IOException ioe) {
System.err.println("IOException: " + ioe.getMessage());
}
}
}
}
당신이'공공의 중괄호 내부의 전체 코드 (찾아) IOException가 {'던졌습니다를 게재 할 수 있습니까? – Sweeper
예외가 다 나와 있습니다! __StackOverflowError__입니다. __IOException__이 아닙니다. 그리고 생성자 안에 객체를 만들지 마라! –
당신은 생성자가 실제로 무엇인지 배우러 가야합니다. – user2357112