java - how to get string from jtable with null cell -


i have jtable , data mysql. in mysql have column allowed null (it's called 'fil'). when retrive data jtable, it's ok. then, want fill jtextarea , enable button if 'fil' not null click jtable row. here code:

private void jtable1mouseclicked(java.awt.event.mouseevent evt) { // todo add handling code here: int row = jtable1.getselectedrow(); string num = jtable1.getvalueat(row, 0).tostring(); string sub = jtable1.getvalueat(row, 1).tostring(); string desc = jtable1.getvalueat(row, 2).tostring(); string start = jtable1.getvalueat(row, 3).tostring(); string end = jtable1.getvalueat(row, 4).tostring(); string sta = jtable1.getvalueat(row, 5).tostring(); string fil = jtable1.getvalueat(row, 6).tostring(); if (fil != "") {   jbutton1.setenabled(true);   jbutton1.settooltiptext(fil); } else {   jbutton1.setenabled(false);   jbutton1.settooltiptext(""); } jtextarea1.settext("subject: " + sub + "\n" + "description: " + "\n" + desc + "\n" + "from " + start + " " + end + "\n" + "status: " + sta);  jlabel3.settext(num); 

the problem when clicked row null 'fil', program give error:

exception in thread "awt-eventqueue-0" java.lang.nullpointerexception 

if (fil != "") { 

should be:

if (fil != null) { 

edit:

string fil = jtable1.getvalueat(row, 6).tostring(); 

you can't invoke tostring() on null object need like:

object filobject = jtable1.getvalueat(row, 6); string fil = (filobject == null) ? "" : filobject.tostring(); 

then use original test:

if (fil != "") 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -