Results 1 to 7 of 7
  1. #1
    alundra is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default solve your problem can not be applied to java.lang.String

    hello ....
    I have a problem with coding yg ni ane d write java

    double w;
    double s;
    double total;

    w = Double.parseDouble (jTextField3.getText ());
    s = Double.parseDouble (jTextField9.getText ());

    total = Double.parseDouble (jTextField9.getText () - jTextField3.getText ()); / / in this section there is an error which says that the operator can not be applied to java.lang.String
    jTextField4.setText (Double.toString (total));

    about what should be changed or added right at ya?
    Please guide her

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: solve your problem can not be applied to java.lang.String

    jTextField9.getText() and jTextField3.getText() are strings, not numbers. And the compiler is telling you that you that you can't subtract string from one another.

    Instead, parse each string and subtract the results.

  3. #3
    alundra is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: solve your problem can not be applied to java.lang.String

    Quote Originally Posted by pbrockway2 View Post
    jTextField9.getText() and jTextField3.getText() are strings, not numbers. And the compiler is telling you that you that you can't subtract string from one another.

    Instead, parse each string and subtract the results.
    sory but u can give me real example wtih my code
    because i am newbie java

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default Re: solve your problem can not be applied to java.lang.String

    Java Code:
    //total = Double.parseDouble (jTextField9.getText () - jTextField3.getText ());
    total = Double.parseDouble (jTextField9.getText ()) - Double.parseDouble (jTextField3.getText ());

  5. #5
    alundra is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: solve your problem can not be applied to java.lang.String

    Quote Originally Posted by pbrockway2 View Post
    Java Code:
    //total = Double.parseDouble (jTextField9.getText () - jTextField3.getText ());
    total = Double.parseDouble (jTextField9.getText ()) - Double.parseDouble (jTextField3.getText ());

    thanks for the instructions, my problem has been solved,
    but I want to ask again
    below why coding is different from the coding that you provide the same when its purpose is to compute a mathematical formula?
    where there is no indication of coding errors

    double a;
    double b;

    a = Double.parseDouble (jLabel6.getText () + jTextField5.getText ()); / / coding that is different from the coding you provided
    jTextField7.setText (Double.toString (a));
    jTextField9.setText (Double.toString (a));

    b = Double.parseDouble (jLabel6.getText () + jTextField5.getText ()); / / / / coding that is different from the coding you provided
    jTextField8.setText (Double.toString (b));
    jTextField10.setText (Double.toString (b));

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: solve your problem can not be applied to java.lang.String

    The + operator concatenates Strings whereas the - operator is invalid for Strings.

    I have a problem with coding yg ni ane d write java
    What?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    alundra is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: solve your problem can not be applied to java.lang.String

    Quote Originally Posted by DarrylBurke View Post
    The + operator concatenates Strings whereas the - operator is invalid for Strings.


    What?

    db

    sory, i am from indonesia so my english language not too good^^
    but thanks for instruction

Similar Threads

  1. Replies: 3
    Last Post: 05-02-2011, 07:51 AM
  2. operator - cannot be applied to java.lang.String,int
    By cc11rocks in forum AWT / Swing
    Replies: 0
    Last Post: 02-11-2011, 03:33 AM
  3. Replies: 5
    Last Post: 10-10-2010, 12:17 AM
  4. Replies: 4
    Last Post: 01-29-2010, 09:57 PM
  5. Error: cannot be applied to (java.lang.String)
    By carl in forum New To Java
    Replies: 1
    Last Post: 08-05-2007, 06:33 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
  •