0


I'm trying to get the page from a HttpsURLConnection to setPage() on a component.

java.lang.ClassCastException: sun.net.www.protocol.http.HttpURLConnection cannot be cast to javax.net.ssl.HttpsURLConnection

That's an error I get.

Any fixes?

URL url = new URL("https://www.lalala.tk/website.html");
HttpsURLConnection httpsConn = (HttpsURLConnection) url.openConnection();
KeirDavis
  • 665
  • 2
  • 10
  • 32
  • Ignoring the fact that there's no way to tell you where you're doing the wrong thing ... the error is telling you exactly what you're doing wrong. You can't magically cast something to something that it isn't – Brian Roach Feb 03 '13 at 10:35

1 Answers1

0

You are importing the wrong class. I bet somewhere in your code there is

import javax.net.ssl.HttpsURLConnection;

But instead, it should be

import sun.net.www.protocol.http.HttpURLConnection;

Try to replace the imports and I am sure it will work out.

poitroae
  • 21,129
  • 10
  • 63
  • 81