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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:57:28+00:00 2026-06-14T16:57:28+00:00

this peice of code initialises X as a new formatter variable. private Formatter X;

  • 0

this peice of code initialises X as a new formatter variable.

 private Formatter X;
     public void Create() {
                    try{
                        X = new Formatter("users.txt");
                        X.format("%1$20s %2$20s %3$20s %4$20s %5$20s %6$20s %7$20s %8$20s %9$20s \n","Firstname","Lastname","Password","ID","Addressln1","Addressln2","Addressln3","EstimatedValue","Tax Owed");
                        System.out.println("Due to there not being any users file present one has been created.");
                    }
                    catch(Exception e){
                        System.out.println("There is a users file present so i will not create another one.");
                    }
                }
            }

This is the piece of code i am having trouble with , at the X.format bit , it keeps giving me a null pointer error and i have tried everything to fix it.

public void WriteToFilecmd(){
                Scanner input = new Scanner(System.in);
                System.out.println("Please enter your First name");
                String Fname = input.next();
                System.out.println("Please enter your Last name");
                String Lname = input.next();
                System.out.println("Please enter your Password");
                String Password = input.next();
                System.out.println("Please enter your user ID");
                String ID = input.next();
                System.out.println("Please enter the first address line of your Property");
                String addressln1 = input.next();
                System.out.println("Please enter the second address line of your Property");
                String addressln2 = input.next();
                System.out.println("Please enter the third address line of your Property");
                String addressln3 = input.next();
                System.out.println("Please enter the properties estimated market value");
                String EstimatedPropertyValue = input.next();
                System.out.println("Please enter your tax owed");
                String Taxowed = input.next();
                input.close();
                X.format("%1$20s %2$20s %3$20s %4$20s %5$20s %6$20s %7$20s %8$20s %9$20s \n",Fname,Lname,Password,ID,addressln1,addressln2,addressln3,EstimatedPropertyValue,Taxowed);


    }
  • 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-14T16:57:30+00:00Added an answer on June 14, 2026 at 4:57 pm

    NullPointerException on the line

    X.format("%1$20s %2$20s %3$20s %4$20s %5$20s %6$20s %7$20s %8$20s %9$20s \n",Fname,Lname,Password,ID,addressln1,addressln2,addressln3,EstimatedPropertyValue,Taxowed);
    

    means either that X itself is null, or the method throws it. Normally, Java foundation classes handle null arguments very well (and Scanner#next() does not return null anyways) and don’t contain bugs, so X is most likely null at the moment it’s being used.

    This could happen if your create method catches an exception (see the console output), you overwrite X later or if you don’t call the create method at all or you call it too late.

    Also note that pokemon exception handling (“gotta catch them all”, catch(Exception e)) is a bad practice. Catch what you can handle, not what you can catch.

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

Sidebar

Related Questions

Try this piece of code - public class WhitespaceTest { public static void main(String[]
Given this piece of code : public static void writeFile(File file,List buffer)throws IOException{ File
I was given this ruby code to overview. I am still new to ruby
I am brand new to Java and was given this piece of code, no
Running this piece of code will print null public class Weird { static class
I'm using this piece of php code to create and rotate an image. And
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
This piece of code is from Adobe docs : package { import flash.display.Loader; import
This piece of code is supposed to go through a list and preform some
This piece of code gives a syntax error at the colon of elif process.loop(i,

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.