1

Hello I want to develope a App for my Team, but I'm getting This Error:

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)

My code is this:

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");

  }
}

I'm using the org.json.simple Library.

The thing is if I'm just calling getEventsdata() and not the Home home = new Home() from my public static void main() than it is working.

Thanks in advance for the help :)

1

1 Answer 1

2

This happens if the call doesn't use the IPv4 stack.

I guess that the Java option -Djava.net.preferIPv4Stack=true would do the trick.

If you are using eclipse set it via the jvm program line arguments

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.