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 8820467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:36:55+00:00 2026-06-14T05:36:55+00:00

I keep getting a NullPointerException every time I run my program and I don’t

  • 0

I keep getting a NullPointerException every time I run my program and I don’t know what to do to get this to work. It is supposed to parse the input file data, do some calculations (all are not coded yet), and then print to an output file.

Here are my classes:

Driver:

public class Driver
{
    public static void main(String[] args) throws IOException
    {
        Analyzer start = new Analyzer();
        start.start();  
    }
}

Analyzer:

public class Analyzer 
{
    public void start() throws IOException
    {       
        int total = 0;
        int totalError = 0;
        final int SIZE = 31;
        Response data[] = new Response[SIZE];

        PrintWriter out = new PrintWriter(new FileWriter("apacheOut.txt"));

        Scanner scan = new Scanner (new File("access_log1.txt"));
        while(scan.hasNext())
        {   
            String address = scan.next();
            scan.next(); //garbage line
            scan.next(); //garbage line

            String date = scan.next() + " " + scan.next(); 

            String temp = scan.next();
            String request = temp.substring(1);
            scan.next(); //garbage line

            int status = 0;
            while(status == 0)
            {
                if(scan.hasNextInt())
                    status = scan.nextInt();
                else
                    scan.next(); //garbage line
            }

            int bytes = 0;
            if(status < 300)
            {
                if(scan.hasNextInt())
                {
                    bytes = scan.nextInt();
                }
                else
                {
                    scan.next(); //garbage line
                } 
            }

            String referAgent = scan.nextLine();

            if(status < 400)
            {
                SuccessResponse srp = new SuccessResponse(address, date, request, status, bytes, referAgent);
            }
            else
            {
                ErrorResponse err = new ErrorResponse(address, date, request, status, bytes, referAgent);
                totalError++;
            }

            total++;    
        }

        int numGet = 0;
        int numPost = 0;
        double numBytes = 0;
        for (int i = 0; i <= SIZE; i++)
        {   
            String address = data[i].getAddress();
            String date = data[i].getDate();
            String request = data[i].getRequest();
            int status = data[i].getStatus();
            int bytes = data[i].getBytes();
            String referAgent = data[i].getReferAgent();

            /** GET/POST count */
            if (request.substring(0,1) == "G")
            {   
                numGet++;
            }
            else if (request.substring(0,1) == "P")
            {
                numPost++;
            }

            /** Number of total bytes */
            numBytes = bytes++;
        }

        out.println ("Warren Smith's Results");
        out.println ("======================");
        out.println ("The total number of requests in the file: " + total);
        out.println ("The total number of GET requests: " + numGet);
        out.println ("The total number of POST requests: " + numPost);
        out.println ("The total number of bytes served: " + numBytes);
        out.println ("The number & percentage of pages producing various status categorizations:" );
        out.println ("    1xx Informational: ");
        out.println ("    2xx Status: ");
        out.println ("    3xx Redirection: ");
        out.println ("    4xx Client Error: ");
        out.println ("    5xx Server Error: ");
        out.println ("The percentage and number of Windows-based clients: ");
        out.println ("The percentage and number of bad requests: " + totalError);
        out.println ("The percentage and number of clients that are Mozilla-based: ");
        out.println ("The percentage and number of requests from the Googlebot: ");

        out.close();
    }
}

Response:

abstract public class Response 
{
    protected String address;
    protected String date;
    protected String request;
    protected int status;
    protected int bytes;
    protected String referAgent;

    /** Response object constructor */
    public Response (String eAddress, String eDate, String eRequest, int eStatus, int eBytes, String eReferAgent)
    {
        address = eAddress;
        date = eDate;
        request = eRequest;
        status = eStatus;
        bytes = eBytes;
        referAgent = eReferAgent;
    }

    /** Returns the IP address */
    public String getAddress()
    {
        return address;
    }

    /** Returns the date */
    public String getDate()
    {
        return date;
    }

    /** Returns the request to server */
    public String getRequest()
    {
        return request;
    }

    /** Returns the status code */
    public int getStatus()
    {
        return status;
    }   

    /** Returns the # of bytes */
    public int getBytes()
    {
        return bytes;
    }

    /** Returns the referring page & agent */
    public String getReferAgent()
    {
        return referAgent;
    }
}

SuccessResponse:

public class SuccessResponse extends Response
{
    /** SuccessResponse object constructor */
    public SuccessResponse (String eAddress, String eDate, String eRequest, int eStatus, int eBytes, String eReferAgent)
    {
        super (eAddress, eDate, eRequest, eStatus, eBytes, eReferAgent);
    }

    /** Returns the IP address */
    public String getAddress()
    {
        return address;
    }

    /** Returns the date */
    public String getDate()
    {
        return date;
    }

    /** Returns the request to server */
    public String getRequest()
    {
        return request;
    }

    /** Returns the status code */
    public int getStatus()
    {
        return status;
    }   

    /** Returns the # of bytes */
    public int getBytes()
    {
        return bytes;
    }

    /** Returns the referring page */
    public String getReferAgent()
    {
        return referAgent;
    }
}

ErrorResponse:

public class ErrorResponse extends Response
{
    /** ErrorResponse object constructor */
    public ErrorResponse (String eAddress, String eDate, String eRequest, int eStatus, int eBytes, String eReferAgent)
    {
        super (eAddress, eDate, eRequest, eStatus, eBytes, eReferAgent);
    }

    /** Returns the request to server */
    public String getRequest()
    {
        return request;
    }

    /** Returns the status code */
    public int getStatus()
    {
        return status;
    }   

    /** Returns the # of bytes */
    public int getBytes()
    {
        return bytes;
    }

    /** Returns the referring page */
    public String getReferAgent()
    {
        return referAgent;
    }
}

The output for this is:

[java] Exception in thread "main" java.lang.NullPointerException
[java]     at Analyzer.start(Unknown Source)
[java]     at Driver.main(Unknown Source)
[java] Java Result: 1

Any ideas why the NullPointerException keeps coming up?

  • 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-14T05:36:57+00:00Added an answer on June 14, 2026 at 5:36 am

    It seems that elements inside data array are not initialized, but you try to call methods using them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting this error when I compile and run my Java program using
I keep getting this java.lang.NullPointerException on the line where mLoginButton's onClickListener is initiated. I
I keep getting this error 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): java.lang.NullPointerException 07-14 23:53:03.653: ERROR/AndroidRuntime(14995): at com.fttech.organizeit.meeting_list$meetingHolder.populateFrom(meeting_list.java:110)
I keep getting an NullPointerException, and I dont know why. what the class is
I keep getting this NPE in my application and I can't seem to get
i keep getting NullPointerException on this line: SharedPreferences myPreference = PreferenceManager.getDefaultSharedPreferences(this); i ran some
I am trying to write program and keep getting a nullPointerException when I call
I am keep getting NullPointerException error at line JSONObject json = userFunctions.uploadFileData(guid, photoName); in
I keep getting 21002 'java.lang.NullPointerException' errors from Apple when I try to test my
Keep getting this error after inserting a subdatasheet into a query and trying to

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.