Results 1 to 3 of 3
  1. #1
    soc86 is offline Member
    Join Date
    Oct 2008
    Posts
    39
    Rep Power
    0

    Default Help!! error message "long cannot be dereferenced"

    I keep getting an error message stating "long can not be dereferenced", I need the barcode all numbers to complete my assignment, any advise please?

    public class Product{

    public static void main (String[]arg){

    String manufact;
    String descript;
    long barCode;
    int price;
    int qty;

    System.out.println("Please enter the manufacturer of your product ");
    manufact=UserInput.readString();

    System.out.println("Please enter the a description of the product ");
    descript=UserInput.readString();

    System.out.println("Please enter the bar code ");
    barCode=UserInput.readLong();

    System.out.println("Please enter the price of your product ");
    price=UserInput.readInt();

    System.out.println("Please enter the quantity of the product you wish to purchase ");
    qty=UserInput.readInt();

    if (manufact.length()==0){
    System.out.println("Error invalid input - manufacturer is blank");
    }
    else if (descript.length()==0){
    System.out.println("Error invalid input - description is blank");
    }

    else if (barCode.length()<12){
    System.out.println("Error invalid input - bar code is to small");
    }
    else if (barCode.length()>14){
    System.out.println("Error invalid input - bar code is to big");
    }
    else if (qty.length()<=0){
    System.out.println("Error invalid input - quantity is not entered");
    }

    else{

    System.out.println(manufact);
    System.out.println(descript);
    System.out.println(barCode);
    System.out.println(qty);

    }

    }

    }

  2. #2
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    As far as I know, you can't do this
    Java Code:
    barCode.length()
    Same for qty.length().

    Use
    Java Code:
    String.valueOf(barCode).length()
    Same for qty.

    ~Matt
    I die a little on the inside...
    Every time I get shot.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Suggestions

    • Are you trying to find out how many numbers there are in the barcode amount/number?


    • Also, why not initialize qty = 0, and then later check if qty == 0?

    Java Code:
    String manufact;
    String descript;
    long barCode;
    int price;
    int qty = 0;
    .
    .
    .
    else if (qty == 0)
    • You are using an int type for the price... it would be more appropaite to use a double type for this (I'll probably get flak from ftr for suggesting this :-).

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  2. Replies: 2
    Last Post: 12-02-2008, 11:06 AM
  3. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  4. Java Loader error message "UNC paths not supported"
    By Johnny562 in forum New To Java
    Replies: 1
    Last Post: 07-01-2008, 10:24 PM
  5. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 06:19 PM

Posting Permissions

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