Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8432015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:00:33+00:00 2026-06-10T06:00:33+00:00

import java.net.*; import java.io.*; public class DjPageDownloader { public URL url; public InputStream is

  • 0
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
            }
        }

    }

this on compilation shows error as:-

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)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:00:35+00:00Added an answer on June 10, 2026 at 6:00 am

    Make all of your fields static if you are just calling them from the Main class. You can’t call an instance field from a static position, as you aren’t currently in an instance. If you wish to keep them non-static, you have to make an instance of DjPageDownloader by putting it in a constructor, and calling that, like so:

    public DjPageDownloader() {
        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
            }
        }
    }
    

    Then call that in your main method:

    public static void main(String []args){
        new DjPageDownloader();//If you use it more later, store to a variable, but atm you aren't
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import java.net.URL; import java.net.URLConnection; import java.sql.*; public class searchlink{ public static void main(String args[])
import java.io.*; import java.net.URL; import java.net.URLConnection; import java.sql.*; public class linksfind{ public static void
import java.io.*; import java.net.*; public class Server{ public static void main(String[] args) throws SocketException,
import java.util.Scanner; public class CourseSplitter { public static void main(String args[]){ Scanner keyboard =
import java.lang.System; public class Splitter{ public static void main(String args[]){ String path_separator = Path
import java.io.*; public class ArrayApp{ public static void main(String[] args){ System.out.println(lllll); } // end
I have the following code: import java.net.InetAddress; public class lookup { public static void
OK so here's the code: import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; public class Main
The client import java.io.*; import java.net.*; import java.util.Scanner; public class HTCPCPClient { public static
I have this test app: import java.applet.*; import java.awt.*; import java.net.URL; public class Test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.