Re: null pointer
"Zachary Mitchell, BCIS" <[email protected]> Sat, 28 Feb 2009 10:41:52 +1030
| Newsgroups | gmane.comp.jakarta.ecs.user |
|---|---|
| Message-ID | <D5AA61171CA8490E9E3750654F456126@zachary> |
No offense, but I would prefer that this email address not be sent to. Please delete references to it, and use: [email protected] instead. Also, I am a source for help with genuine problems/ code problems. I am unfortunately not a source as a debugger! :) ----- Original Message ----- From: "Thufir" <[email protected]> To: <[email protected]> Sent: Friday, February 27, 2009 9:29 PM Subject: null pointer > Would there a be a better approach to this class? > > It's just supposed to output a result set. however, since there has to > be an update mechanism, I figured that might as well be incorporated as > well. > > One thing I notice is that there's no real need to extend table, so I > think I'm taking maybe a bad approach. > > Also, I'm getting a null pointer error further down, commented in CAPS. > At first the data is good, then a null value. Oh, maybe the start of a > nonexistent column? Not sure. > > > import a00720398.util.EnumOfMethods; > import java.awt.Color; > import java.sql.ResultSet; > import java.sql.ResultSetMetaData; > import java.sql.SQLException; > import java.util.logging.Level; > import java.util.logging.Logger; > import org.apache.ecs.html.*; > > public class SimpleResultSetTable extends Table { > > private static final boolean isPretty = true; > private static final long serialVersionUID = 1L; > private TR tr = new TR(); > private ResultSet resultSet = null; > private ResultSetMetaData resultSetMetaData = null; > private int colCount = 1; > > private static Logger logger = Logger.getLogger > (SimpleResultSetTable.class.getName()); //Controller.class.getName() > > > private Form getDeleteButtonForm(int id) { > EnumOfMethods enumVal = EnumOfMethods.D; > String action = "/Assignment"; > String method = "get"; > Form form = new DeleteButtonForm(action, method, enumVal, id); > return form; > } > > private void header() throws SQLException { > for (int i = 1; i <= colCount; i++) { > TH th = new TH(); > th.setPrettyPrint(isPretty); > th.addElement(resultSetMetaData.getColumnName(i)); > addElement(th); > } > } > > private String getHex(Color color){ > return Integer.toHexString(color.getRGB() & 0x00ffffff); > } > > private Form getElementForm(){ > Form form = new ElementForm(); > return form; > } > > private void data() throws SQLException { > resultSet.beforeFirst(); > while (resultSet.next()) { > tr = new TR(); > tr.setPrettyPrint(isPretty); > int i = resultSet.getRow(); > Color color = (i % 2 == 0) ? Color.LIGHT_GRAY : Color.GRAY; > String colorString = getHex(color); > tr.setBgColor(colorString); > > for (int j = 1; j <= colCount; j++) { > TD td = new TD(); > td.setPrettyPrint(isPretty); > String element = resultSet.getString(j);//String.valueOf > (j); // > if (j == 1) { > int id = Integer.parseInt(element); > Form form = this.getDeleteButtonForm(id); > td.addElement(form); > } else { > > //NULL POINTER ERROR RIGHT HERE > //I'M NOT SURE WHY ELEMENT IS LITERALLY NULL, > //BUT IT IS. THERE'S GOOD DATA AT FIRST, THEN > //A NULL VALUE > > logger.log(Level.WARNING, "why null?\t" + element); > Form form = new ElementForm(element, 1,2); > //form.addElement(element); > td.addElement(form); > } > tr.addElement(td); > addElement(tr); > } > } > } > > public SimpleResultSetTable(ResultSet rs) throws SQLException { > setBorder(1); > setPrettyPrint(isPretty); > resultSet = rs; > resultSetMetaData = rs.getMetaData(); > colCount = resultSetMetaData.getColumnCount(); > header(); > data(); > } > } > > > > > thanks, > > Thufir > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] >