-
August 3rd, 2017, 12:49 PM
#1
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
-
August 3rd, 2017, 08:16 PM
#2
Re: Jtable retruning nulls
What are the values of the variables on that line? What is the value returned by the getValueAt method?
Norm
-
August 4th, 2017, 07:32 AM
#3
Re: Jtable retruning nulls
Originally Posted by Azoth
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
-
August 4th, 2017, 07:50 AM
#4
Re: Jtable retruning nulls
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
-
August 4th, 2017, 10:53 AM
#5
Re: Jtable retruning nulls
The statement (9219) returns
1
2
3
-
August 4th, 2017, 11:24 AM
#6
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
-
August 4th, 2017, 05:28 PM
#7
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.
-
August 4th, 2017, 06:52 PM
#8
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
-
August 6th, 2017, 10:14 AM
#9
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
-
August 6th, 2017, 10:25 AM
#10
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
-
August 6th, 2017, 11:46 AM
#11
Re: Jtable retruning nulls
I get
2
3
4
for
Code:
(StatsTable.getValueAt(i,0)
-
August 6th, 2017, 11:54 AM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|