Jtable retruning nulls
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: Jtable retruning nulls

  1. #1
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Jtable retruning nulls

    I have this code here:
    Code:
    try{
           for(int i=0;  i<=rows;++i)
        {
           if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
          data[i]=Double.parseDouble(StatsTable.getValueAt(i, 3).toString());
          
          df++;
         
     
         }
           
          }catch(Exception e)   {simplelogger(e);
           JOptionPane.showMessageDialog(null,"Input error: see err.log  for more info.");
          }
    It is duplicated in different parts of my program. It gives me the following errors

    java.lang.NullPointerException
    at MycologyFrame.jPerfromTestButActionPerformed(MycologyFrame.java:9219)
    at MycologyFrame.access$20200(MycologyFrame.java:50)
    at MycologyFrame$204.actionPerformed(MycologyFrame.java:6718)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)

    Now line 90219 is
    Code:
     if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
    Help

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    What are the values of the variables on that line? What is the value returned by the getValueAt method?
    Norm

  3. #3
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Re: Jtable retruning nulls

    Quote Originally Posted by Azoth View Post
    I have this code here:
    Code:
    try{
           for(int i=0;  i<=rows;++i)
        {
           if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
          data[i]=Double.parseDouble(StatsTable.getValueAt(i, 3).toString());
          
          df++;
         
     
         }
           
          }catch(Exception e)   {simplelogger(e);
           JOptionPane.showMessageDialog(null,"Input error: see err.log  for more info.");
          }
    It is duplicated in different parts of my program. It gives me the following errors

    java.lang.NullPointerException
    at MycologyFrame.jPerfromTestButActionPerformed(MycologyFrame.java:9219)
    at MycologyFrame.access$20200(MycologyFrame.java:50)
    at MycologyFrame$204.actionPerformed(MycologyFrame.java:6718)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)

    Now line 90219 is
    Code:
     if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
    Help
    It should be
    1
    2
    3
    .
    .

    Like a spreadsheet

  4. #4
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    It should be
    Ok, but what were the actual values?
    What variable had the null value?
    Add a print statement before the statement (9219) where the NPE happened that prints out the values of the variables and the value returned by the get method so you can see where the null value is.
    Norm

  5. #5
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Re: Jtable retruning nulls

    The statement (9219) returns
    1
    2
    3

  6. #6
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    Ok none of those printed values are null.
    What variable did those values come from?
    What are the values in the other variables used on line 9219?
    Print the values in these to see:
    StatsTable
    StatsTable.getValueAt(i,0)
    i

    You need to find where the null value is to be able to solve the problem. Printing the values will help you find it.
    Norm

  7. #7
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Re: Jtable retruning nulls

    The values
    1
    2
    3
    came from the the code
    Code:
    if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
    When printing out i I get
    0
    1
    2
    3
    I then changed the loop to
    Code:
     (for  i=ii<rows;++i)
    System.out.print(i);
    and got
    1
    2
    3
    ..
    with the same problem arrg
    Last edited by Azoth; August 4th, 2017 at 05:40 PM.

  8. #8
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    Print the values of these just before line 9219 to see where the null value is:
    StatsTable
    StatsTable.getValueAt(i,0)
    i

    What were the values of the above variables just before the NPE happened?
    You need to find where the null value is to be able to solve the problem. Printing the values will help you find it.


    A cell can contain a null value. Do not call the toString() method with the getValueAt method returns a null value.
    Last edited by Norm; August 4th, 2017 at 07:01 PM.
    Norm

  9. #9
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Re: Jtable retruning nulls

    javax.swing.JTable[,0,0,606x160,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.MatteBorder@129d20b,flags=251658560,maximumSize=,minimumSize=,preferredSize=,autoCreateColumnsFromModel=true,autoResizeMode=AUTO_RESIZE_SUBSEQUENT_COLUMNS,cellSelectionEnabled=false,editingColumn=3,editingRow=3,gridColor=java.awt.Color[r=0,g=0,b=0],preferredViewportSize=java.awt.Dimension[width=450,height=400],rowHeight=16,rowMargin=0,rowSelectionAllowed=true,selectionBackground=DerivedColor(color=57,105,138 parent=nimbusSelectionBackground offsets=0.0,0.0,0.0,0 pColor=57,105,138,selectionForeground=DerivedColor(color=255,255,255 parent=nimbusLightBackground offsets=0.0,0.0,0.0,0 pColor=255,255,255,showHorizontalLines=true,showVerticalLines=true]
    javax.swing.JTable[,0,0,606x160,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.MatteBorder@129d20b,flags=251658560,
    Here is printo out of StatsTable

    maximumSize=,minimumSize=,preferredSize=,autoCreateColumnsFromModel=true,autoResizeMode=AUTO_RESIZE_SUBSEQUENT_COLUMNS,cellSelectionEnabled=false,editingColumn=3,editingRow=3,gridColor=java.awt.Color[r=0,g=0,b=0],preferredViewportSize=java.awt.Dimension[width=450,height=400],rowHeight=16,rowMargin=0,rowSelectionAllowed=true,selectionBackground=DerivedColor(color=57,105,138 parent=nimbusSelectionBackground offsets=0.0,0.0,0.0,0 pColor=57,105,138,selectionForeground=DerivedColor(color=255,255,255 parent=nimbusLightBackground offsets=0.0,0.0,0.0,0 pColor=255,255,255,showHorizontalLines=true,showVerticalLines=true]
    javax.swing.JTable[,0,0,606x160,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.MatteBorder@129d20b,flags=251658560,maximumSize=,minimum

  10. #10
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    Is that the value of the varaible: StatsTable?
    Ok, that's one of the three, what about the value of this one:
    StatsTable.getValueAt(i,0)
    Last edited by Norm; August 6th, 2017 at 10:27 AM.
    Norm

  11. #11
    Join Date
    Feb 2017
    Location
    Montreal
    Posts
    38

    Re: Jtable retruning nulls

    I get
    2
    3
    4
    for
    Code:
     (StatsTable.getValueAt(i,0)

  12. #12
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,741

    Re: Jtable retruning nulls

    If the NPE happens on this line
    if (Integer.parseInt(StatsTable.getValueAt(i,0).toString()) != 0)
    and none of the variables have a null value,

    I don't understand why you are getting a NPE. There needs to be a null value somewhere.
    Norm

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)