Здравствуйте, я хочу разработать приложение для своей команды, но получаю эту ошибку:
java.net.SocketException: Address family not supported by protocol family: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:606)
at java.net.Socket.connect(Socket.java:555)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:463)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:558)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
at sun.net.www.http.HttpClient.New(HttpClient.java:339)
at sun.net.www.http.HttpClient.New(HttpClient.java:357)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1226)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1162)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1056)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:990)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1570)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1498)
at java.net.URL.openStream(URL.java:1067)
at de.tbprivi.mgde.Home.Home.getEventData(Home.java:37)
at de.tbprivi.mgde.Home.Home.<init>(Home.java:29)
at de.tbprivi.mgde.main.Main.main(Main.java:8)
Мой код:
package de.tbprivi.mgde.Home;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class Home {
public JFrame frame;
private JSONParser parser;
public Home(){
frame = new JFrame();
frame.setTitle("Miners-Games.de - TEAM APP");
frame.setSize(700,500);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
try {
getEventData();
} catch (IOException | ParseException e) {
e.printStackTrace();
}
}
private void getEventData() throws IOException, ParseException {
Object obj = parser.parse(new InputStreamReader(new URL("http://mylink.com/events.json").openStream()));
JSONObject file = (JSONObject) obj;
file.get("events");
}
}
Я использую org. json .simple Library.
Дело в том, что если я просто вызываю getEventsdata () , а не Home home = new Home () из my publi c stati c void main () чем он работает.
Заранее благодарим за помощь :)