Results 1 to 2 of 2
  1. #1
    knightwriter is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default I'm not sue why this isn't working.

    I am instantiating an object "list" from the Shopkeeper class. I'm trying to get the user to type in a specific item and then have a total that outputs the total of the items they purchased. (I'm learning Java on my own and believe I have the terminology correct.) Here is the code.

    package dark.dominion;

    import java.util.Scanner;
    import java.lang.System;

    public class Shopkeeper
    public static void list(){

    int rope = 1;
    int bedroll = 3;
    int rations = 2;
    int total = 0;
    String list = "";

    System.out.println("Welcome to my shop. We have rope, a bedroll"
    + " and rations. Type the name of the items you want.");

    Scanner keyboard = new Scanner(;
    list = keyboard.nextLine();

    total = Integer.parseInt(list);

    System.out.println("Your total is: " + total);

    I am using netbeans and here are the error messages:

    Exception in thread "main" java.lang.NumberFormatException: For input string: "bedroll"
    at java.lang.NumberFormatException.forInputString(Num
    at java.lang.Integer.parseInt(
    at java.lang.Integer.parseInt(
    at dark.dominion.Shopkeeper.list(
    at dark.dominion.DarkDominion.main( 44)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 10 seconds)

    Thanks for any and all help!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    On vacation
    Rep Power

    Default Re: I'm not sue why this isn't working.

    NumberFormatException: For input string: "bedroll"
    The parseInt() method doesn't think the String: "bedroll" has a vaid NumberFormat.
    You should enter numeric digits and not letters.

Similar Threads

  1. Collisions are working & not working
    By Jayayoh in forum Java 2D
    Replies: 1
    Last Post: 06-24-2011, 05:21 PM
  2. Why isn't this working?
    By nickburris in forum New To Java
    Replies: 14
    Last Post: 02-03-2011, 03:00 AM
  3. Replies: 2
    Last Post: 01-04-2011, 05:30 AM
  4. This Is Not Working.
    By FatalSylence in forum New To Java
    Replies: 8
    Last Post: 10-16-2010, 02:15 AM
  5. Replies: 8
    Last Post: 05-28-2008, 07:00 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