Results 1 to 3 of 3
  1. #1
    miss_peaches is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Exception in thread main

    I keep getting this error message and don't know where to begin to fix it. Please help. The entire error says Exception in thread at java util.Formatter$FormatSpecifier at java.util.Formatter$FormatSpecifier.checkInteger(U nknown Source)
    at java.util.Formatter$FormatSpecifier.<init>(Unknown Source)
    at java.util.Formatter.parse(Unknown Source)
    at java.util.Formatter.format(Unknown Source)
    at Source)
    at Source)
    Here is the code:

    Java Code:
     * The AddressBookApp1 class implements an application that
     * simply prints address and charitable donations for 5 individuals
     * and terminates. If a negative value is entered, the user is 
     * prompted to enter a positive value.
    class AddressBookApp1 {
    	// main method begins program execution
        	public static void main(String[] args) {
            //create scanner to obtain input from command window
    	java.util.Scanner input = new java.util.Scanner (;
    	String name; 	// Donor's name
    	String address;	// Donor's address
    	String city;	// City where donor lives
    	String state;	// State where donor lives
    	int zipcode;	// Zipcode of owner's address
    	int numDonat;	// Number of donations
    	int amtDonat;	// Dollar amount of donations
    	int nameCounter;// Number of names to be entered
    	double total;	// Total amount of donations this year
    	// initialization phase
    	name = "Name"; 
    	address = "Address";
    	city = "City";
    	state = "State";
    	zipcode = 0;
    	nameCounter = 1;
    	total = 0;
    	amtDonat = 0;
    	numDonat = 0;
    	// processing phase
    	for (nameCounter = 1; nameCounter <= 5; ++nameCounter) // loop 5 times
    	   System.out.print ("Enter the donor's name:"); //prompt
    	   name = input.nextLine(); // read donor's name from user input
      	   System.out.print ("Enter donor's address:"); //prompt
               address = input.nextLine(); // read address from user input
               System.out.print ("Enter donor's city:"); //prompt
               city = input.nextLine(); // read city from user input
    	   System.out.print ("Enter donor's state:"); // prompt
    	   state = input.nextLine(); // read state from user input
    	   System.out.print ("Enter donor's zipcode:"); //prompt
    	   zipcode = input.nextInt(); // read zipcode from user input
    	   System.out.print ("Enter the number of donations this year:"); //prompt
    	   numDonat= input.nextInt(); // read number of donations from user input
    		if (amtDonat <= -1)
    		   System.out.print ("Number must be positive. Please re-enter:"); 
    	   	   System.out.print ("Enter dollar amount of donations:"); 
    	           amtDonat= input.nextInt(); // read donation amount from user input
    		if (numDonat<= -1)
    		   System.out.print ("Amount must be positive. Please re-enter:"); //prompt
    	   System.out.print ("The donor, whose name is"+ name);
    	   System.out.print ("and resides at"+ address);
    	   System.out.print ("in the city of"+ city);
    	   System.out.print ("in the state of"+ state);
    	   System.out.print ("with a zipcode of"+ zipcode);
    	   System.out.print ("has donated $"+ total);
    	   System.out.println ("this year!");
    	   total = amtDonat * numDonat;
    	} //end for
    	} // end main method
    } // end class AddressBookApp1

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Which line throws the exception? And does it get thrown immediately? Or after some input?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    The error didn't come from that code. Post the actual code you were running when you got the error.


Similar Threads

  1. Replies: 28
    Last Post: 03-16-2011, 07:06 PM
  2. Exception in thread main
    By maya700 in forum New To Java
    Replies: 14
    Last Post: 06-27-2010, 07:59 PM
  3. Replies: 6
    Last Post: 07-16-2009, 03:30 PM
  4. Replies: 1
    Last Post: 07-16-2009, 10:35 AM
  5. Replies: 1
    Last Post: 08-07-2007, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts