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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:06:22+00:00 2026-06-01T21:06:22+00:00

I am getting a Null Pointer Exception Error at line 23 and line 78

  • 0

I am getting a Null Pointer Exception Error at line 23 and line 78 in Main and getRank() respectively. This occurred when I reorganized the code and made the method getRank(). This code compiled and ran previous to my moving the code to the getRank() method, and I believe this error is due to a variable not being initialized properly.

import java.io.*;
import java.util.*;

public class NameRecord
{
    private static String num, name = "dav";
    private static String [] fields;
    private static int [] yearRank;
    private static boolean match;
    private static int getInts, marker, year, max;

        public static void main( String[] args)
        {
            java.io.File file = new java.io.File("namesdata.txt");
            try
            {
                Scanner input = new Scanner(file);
                while (input.hasNext())
                {
                    String num = input.nextLine();
                    if(match = num.toLowerCase().contains(name.toLowerCase()))
                    {
                        getRank();//My Problem I believe
                        getBestYear(marker);
                        System.out.printf("%s     %d     %d\n",fields[0],year,max);
                    }
                }
            }
            catch(FileNotFoundException e)
            {
                System.err.format("File does not exist\n");
            }
        }



    public static int getRank()
    {
        fields = num.split(" ");
        max = 0;
        for (int i = 1; i<12; i++)
        {   
            getInts = Integer.parseInt(fields[i]);
            if(getInts>max)
            {
                max = getInts;
                marker = i;
            }
        }
        return max;
    }
}
  • 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-01T21:06:24+00:00Added an answer on June 1, 2026 at 9:06 pm

    Your problem is with num, you declare a local variable in main which hides your instance member:

    String num = input.nextLine();
    

    You probably meant:

    num = input.nextLine();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Exception in thread main java.lang.NullPointerException at com.hibernate.UserDAO.findAll(UserDAO.java:154) at test.main(test.java:12) I am getting this error
Hi i am reading inbox using service but i m getting null pointer exception
I'm Getting a Null Pointer Exception while canceling the Progress Dialog in Async Task
I am getting a null pointer exception report in the android developer console. I
I need help finding why I'm getting a null pointer exception. I've tried going
Ok so at the moment I'm getting a null pointer exception when adding to
I am getting a nullpointerexception error on this line btn10.setOnClickListener(this); this is the entire
Im trying to work with following code i getting this error at xsltProcessor.importStylesheet Error
I'm getting an error of a NullPointerException and it is referencing the line Camera.Parameters:
Guys i need some help here , im getting this error here at the

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.