Results 1 to 6 of 6
  1. #1
    Link01 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default Been working on a code for days

    Still not working the error has changed day to day but it still wont work

    I know what the problem is it is with declaring variables and it must be in the button code for it to work apparently

    this is what I found but it does not work

    Integer iMiles = new integer();
    Integer iFuelConsumption = new Integer();
    Integer iMilesPerGallon = new Integer();

    i tried

    int imiles;

    but still no luck I am reaching boiling point here

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    If the value can be null, use Integer.
    If the value will never be null, use int.

    You declare an int by writing

    Java Code:
    int miles = 42;
    and
    Java Code:
    Integer miles = 42;
    for Integer.
    If you want more help then post the error message that you getting together with the code for it.

  3. #3
    Link01 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    If the value can be null, use Integer.
    If the value will never be null, use int.

    You declare an int by writing

    Java Code:
    int miles = 42;
    and
    Java Code:
    Integer miles = 42;
    for Integer.
    If you want more help then post the error message that you getting together with the code for it.
    with the first two the user input values textboxes become the variable

    with the third the variable becomes a label

    and it moved the error to the main code saying int can not de dereference or what ever it said

    (I'm using net beans)
    Last edited by Link01; 05-19-2010 at 12:57 PM.

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by Link01 View Post
    with the first two the user input values textboxes become the variable

    with the third the variable becomes a label
    That does not make any sense.

    If you have textfields, they give you their value through the getText method which returns a String. You can parse that string to an int using the Integer.parseInt method.
    But I'm now guessing at what you are trying to do.
    Rather you explain fully what you are trying to do and where you are stuck.

  5. #5
    Link01 is offline Member
    Join Date
    May 2010
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    That does not make any sense.

    If you have textfields, they give you their value through the getText method which returns a String. You can parse that string to an int using the Integer.parseInt method.
    But I'm now guessing at what you are trying to do.
    Rather you explain fully what you are trying to do and where you are stuck.
    int iMiles = 0;
    int iFuelConsumption = 0;
    int iMilesPerGallon= 0;

    iMiles.parseInt(miles.getText());
    iFuelConsumption.parseInt(fuel.getText());


    iMilesPerGallon = iMiles/iFuelConsumption;
    mpg.setText(iMilesPerGallon.toString());

    it is a fuel efficiency program i'm stuck getting the textfields and label to link to the variables

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    what ever it said
    Its better to copy and paste the FULL text of the error message here. Hard to guess what the problem is with the above.

    Note on your last posting. Several primitives are used as objects: iMilesPerGallon is not an object and does not have methods.

    See the Integer class for static conversion methods to do some of the above.
    Last edited by Norm; 05-19-2010 at 04:58 PM.

Similar Threads

  1. Replies: 6
    Last Post: 11-12-2009, 11:50 AM
  2. Why is the code not working
    By sanox in forum New To Java
    Replies: 12
    Last Post: 09-08-2009, 12:28 PM
  3. Next Page Code is not working
    By Java.child in forum AWT / Swing
    Replies: 2
    Last Post: 02-18-2009, 06:26 PM
  4. JNI: Why this code not working?
    By playwin2 in forum Advanced Java
    Replies: 5
    Last Post: 11-25-2008, 02:12 PM
  5. My code is not working properly ..modify it
    By Shyam Singh in forum New To Java
    Replies: 14
    Last Post: 07-16-2008, 06:48 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
  •