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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:38:30+00:00 2026-06-13T12:38:30+00:00

My code looks good enough to me, but I keep getting a nullpointerexception. I’m

  • 0

My code looks good enough to me, but I keep getting a nullpointerexception. I’m inputting a text file that looks like this:

Kermit D.Frogge 17.25 5.25 0.0 8.0 1.5 8.0 2.25 7.75 0.0 8.0 2.0

This is some of my code:

private static BufferedReader br;
private static StringTokenizer strTkn;


private static String st, firstName, middleInitial, lastName;
private static double monRegHours, monOverHours, tuesRegHours, tuesOverHours,      wedRegHours, wedOverHours,
thurRegHours, thurOverHours, friRegHours, friOverHours;
private static double totalRegHours, totalOverHours, hourlyWage, regularPay, overtimePay, weeklyPay;
private static JFileChooser chooser;


public static void main (String args []) throws IOException 
{
chooser();
getData();
calcpay();
printresult();
}


public static void chooser() throws IOException
{
JFileChooser chooser=new  JFileChooser();
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION) 
{
  File f = chooser.getSelectedFile();
  br=new BufferedReader(new FileReader(f));
  st="";
  while((st=br.readLine())!=null);
  {
    System.out.println ("Data Line = " + st ); //print the whole line
  }
  }
  }


public static void getData() throws IOException
{
 strTkn = new StringTokenizer(st, " .");

 firstName = strTkn.nextToken();
 middleInitial = strTkn.nextToken();
 lastName = strTkn.nextToken();
 hourlyWage = Double.parseDouble(strTkn.nextToken());

 monRegHours = Double.parseDouble(strTkn.nextToken());
 monOverHours = Double.parseDouble(strTkn.nextToken());

 tuesRegHours = Double.parseDouble(strTkn.nextToken());
 tuesOverHours = Double.parseDouble(strTkn.nextToken());

 wedRegHours = Double.parseDouble(strTkn.nextToken());
 wedOverHours = Double.parseDouble(strTkn.nextToken());

 thurRegHours = Double.parseDouble(strTkn.nextToken());
 thurOverHours = Double.parseDouble(strTkn.nextToken());

 friRegHours = Double.parseDouble(strTkn.nextToken());
 friOverHours = Double.parseDouble(strTkn.nextToken());


}


public static void calcpay()
{
totalRegHours = monRegHours + tuesRegHours + wedRegHours + thurRegHours + friRegHours;
totalOverHours = monOverHours + tuesOverHours + wedOverHours + thurOverHours +    friOverHours;

overtimePay = round(totalOverHours * (1.5 * hourlyWage));
regularPay  = round(hourlyWage * totalRegHours);
weeklyPay = regularPay + overtimePay;
}


public static void printresult()
{
System.out.println("Name: " + firstName + " " + middleInitial + " " + lastName);
System.out.printf("Weekly Pay: " + "$%.2f\n", weeklyPay);
//this allows me to print $x.50 instead of $x.5, and not have repeating decimals
}


public static double round(double num) 
{
// rounding to two decimal places
num *= 100;
int rounded = (int) Math.round(num);
return rounded/100.0;

Sorry if it looks bad, my computer doesn’t like to copy paste

  • 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-13T12:38:31+00:00Added an answer on June 13, 2026 at 12:38 pm

    It is a very simple error. You have placed a semicolon after your while loop.

    while((st=br.readLine())!=null);
    

    Remove the semi-colon and it will work fine.

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

Sidebar

Related Questions

My code looks somehow like this: //INCLUDES FILE *file; void handlesocket(int socket); int main(int
I have a piece of code that looks like this: ipCount = defaultdict(int) for
Is my code good enough to display text above image? It looks similar to
I'm looking for a good T-SQL Pretty Printer so that all the code looks
Code looks like that #include <cstdlib> #include <iostream> using namespace std; #define n 3;
My code looks like this : Vector<String> My_Vector=new Vector<String>(); String My_Array[]=new String[100]; for (int
My code looks like this: NSIndexPath *ip = [NSIndexPath indexPathForRow:15 inSection:0]; [[self tableView] selectRowAtIndexPath:ip
I was given a block of c++ code that looks like it was from
I ran into some (production!) code that looks like the snippet below: synchronized(some_object) {
My code looks fine but it is not working as it should because update

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.