1

I'm running a simple CodenameOne app where an image is downloaded and displayed in the form.

'

int WIDTH = Display.getInstance().getDisplayWidth();
        Form f = new Form();
        f.getToolbar().hideToolbar();
        f.getStyle().setBgColor(0xFFFFFF);
        EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(WIDTH, WIDTH), false);
        URLImage puppyImage = URLImage.createToStorage(placeholder, "puppy.png", "https://images.newscientist.com/wp-content/uploads/2021/06/03141753/03-june_puppies.jpg?crop=1:1,smart&width=1200&height=1200&upscale=true");
        Container imageContainer = new Container();
        imageContainer.add(puppyImage);
        f.add(imageContainer);
        f.show();

'

I'm not sure what I'm doing incorrectly (or did incorrectly), while I used a proxy everything ran fine, and the image is downloaded and saved. Now if I run the app without the proxy I get the following error and stack trace:

'

java.net.ConnectException: Connection refused: connect
    at java.base/java.net.PlainSocketImpl.connect0(Native Method)
    at java.base/java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:101)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
    at java.base/java.net.Socket.connect(Socket.java:608)
    at java.base/java.net.Socket.connect(Socket.java:557)
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:182)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
    at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:526)
    at java.base/sun.net.www.http.HttpClient$1.run(HttpClient.java:524)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(HttpClient.java:523)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:564)
    at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265)
    at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:212)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1208)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:189)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1592)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
    at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:527)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:334)
    at com.codename1.impl.javase.JavaSEPort.getResponseCode(JavaSEPort.java:10179)
    at com.codename1.io.ConnectionRequest.performOperationComplete(ConnectionRequest.java:905)
    at com.codename1.io.NetworkManager$NetworkThread.runCurrentRequest(NetworkManager.java:314)
    at com.codename1.io.NetworkManager$NetworkThread.run(NetworkManager.java:390)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

' I would like to know what is causing this and how I can fix it, Thanks.

2
  • 1
    It's possible the server is blocking requests that look suspicious or that the you're behind a proxy that's preventing the connection from going through. Make sure to configure your Java proxy settings and also check out the simulators network monitor for deeper details about the incoming/outgoing traffic. Commented Jul 13, 2022 at 1:45
  • Thanks for the advice. When I run the simple app on my device it runs flawless. So I'll work with it as is until I can rectify it better. Thanks again. Commented Jul 15, 2022 at 18:28

1 Answer 1

1

Found the issue! I realized I manually set proxy settings in the simulator.

Codename One Simulator Network Proxy Settings

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.