hello hello - 4 months ago 48
Android Question

Cannot resolve method openConnection()

I'm trying to download web content from a URL using the code below:

URL content = new URL(urlstr);
HttpURLConnection urlConnection = (HttpURLConnection) content.openConnection();

try {
InputStream in = urlConnection.getInputStream();
InputStreamReader isw = new InputStreamReader(in);

String existing_string = "";
StringBuilder builder = new StringBuilder(existing_string);
int data = isw.read();
while (data != -1) {
char current = (char) data;
data = isw.read();

The error I get is
Cannot resolve method openConnection()
. Import statements look like this:

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;

I have look at ALMOST all SO related questions on this, but I dont seem to get it working.


You must have a class of your own called URL, possibly this one. Don't do that. Don't use existing JDK class names for your own.