import java.net.*;
import java.io.*;
public class DjPageDownloader {
public URL url;
public InputStream is = null;
public DataInputStream dis;
public String line;
public static void main(String []args){
try {
url = new URL("http://stackoverflow.com/");
is = url.openStream(); // throws an IOException
dis = new DataInputStream(new BufferedInputStream(is));
while ((line = dis.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
这在编译时显示错误为:-
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Cannot make a static reference to the non-static field url
Cannot make a static reference to the non-static field is
Cannot make a static reference to the non-static field url
Cannot make a static reference to the non-static field dis
Cannot make a static reference to the non-static field is
Cannot make a static reference to the non-static field line
Cannot make a static reference to the non-static field dis
Cannot make a static reference to the non-static field line
Cannot make a static reference to the non-static field is
at djPageDownloader.DjPageDownloader.main(DjPageDownloader.java:16)