Results 1 to 8 of 8
  1. #1
    lpt2007 is offline Member
    Join Date
    Nov 2016
    Posts
    31
    Rep Power
    0

    Default trying to calculate jTable row

    My code: I get error: Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "10,10"
    Java Code:
    public BlagajnaVnos() {
            initComponents();
            retreve();
            jTextField4.setText(Integer.toString(getSum()));
              
        }
        
        public int getSum(){
            int rowsCount = jTable1.getRowCount();
            int sum = 0;
            for(int i = 0; i < rowsCount; i++){
                sum = sum+Integer.parseInt(jTable1.getValueAt(i, 3).toString());
            }
            return sum;
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: trying to calculate jTable row

    That value is not a valid integer.

    When posting exceptions you should also tell us what line in your code it is thrown from.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    lpt2007 is offline Member
    Join Date
    Nov 2016
    Posts
    31
    Rep Power
    0

    Default Re: trying to calculate jTable row

    Quote Originally Posted by Tolls View Post
    That value is not a valid integer.

    When posting exceptions you should also tell us what line in your code it is thrown from.
    How I can calculate values like this: 10,10?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: trying to calculate jTable row

    Well, assuming you want to keep the decimal value then you ought to be using a Double.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    lpt2007 is offline Member
    Join Date
    Nov 2016
    Posts
    31
    Rep Power
    0

    Default Re: trying to calculate jTable row

    Can you show me how to use Double in my code?

  6. #6
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,993
    Rep Power
    9

    Default Re: trying to calculate jTable row

    Java Code:
    double value = Double.parseDouble( yourString )
    This wil use the default Locale. If you need more control over what format you will be parsing, you need a NumberFormat
    Java Code:
    NumberFormat dutch = NumberFormat.getInstance( new Locale("nl"));
    double value = dutch.parse( yourString ).doubleValue();
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  7. #7
    lpt2007 is offline Member
    Join Date
    Nov 2016
    Posts
    31
    Rep Power
    0

    Default Re: trying to calculate jTable row

    Sorry but I do not following you. Can you please show me how in my code?

    Java Code:
    public BlagajnaVnos() {
            initComponents();
            retreve();
            jTextField4.setText(Integer.toString(getSum()));
               
        }
         
        public int getSum(){
            int rowsCount = jTable1.getRowCount();
            int sum = 0;
            for(int i = 0; i < rowsCount; i++){
                sum = sum+Integer.parseInt(jTable1.getValueAt(i, 3).toString());
            }
            return sum;
        }

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: trying to calculate jTable row

    Presumably you wrote that code, so you should know where it is you need to parse a double.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Calculate PI
    By Nasima Ferdous Tripti in forum New To Java
    Replies: 4
    Last Post: 06-19-2014, 08:37 PM
  2. Replies: 4
    Last Post: 04-02-2012, 08:57 PM
  3. calculate fft
    By ram.west in forum Advanced Java
    Replies: 2
    Last Post: 08-27-2008, 04:05 AM
  4. Replies: 2
    Last Post: 05-15-2008, 11:15 AM
  5. Calculate what e1 and e2 should be
    By Legoland in forum New To Java
    Replies: 11
    Last Post: 07-02-2007, 07:01 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
  •