Osiris93
Osiris93

Reputation: 189

Cannot fix the null 'key' argument to get graph to generate

I have a graph that will display a comparison between quotes and invoices linked to an employee number within a certain time period. When I run the application, I get this infamous error message:

java.lang.IllegalArgumentException: Null 'key' argument. at org.jfree.chart.util.ParamChecks.nullNotPermitted(ParamChecks.java:65) at org.jfree.data.DefaultKeyedValues.setValue(DefaultKeyedValues.java:234) at org.jfree.data.DefaultKeyedValues2D.setValue(DefaultKeyedValues2D.java:341) at org.jfree.data.category.DefaultCategoryDataset.setValue(DefaultCategoryDataset.java:262) at org.jfree.data.category.DefaultCategoryDataset.setValue(DefaultCategoryDataset.java:278) at SV_ManagerDivision.SV_ManagerEmpPerformance.monthGraph(SV_ManagerEmpPerformance.java:577) at SV_ManagerDivision.SV_ManagerEmpPerformance.btnViewQIActionPerformed(SV_ManagerEmpPerformance.java:303) at SV_ManagerDivision.SV_ManagerEmpPerformance.access$200(SV_ManagerEmpPerformance.java:24) at SV_ManagerDivision.SV_ManagerEmpPerformance$3.actionPerformed(SV_ManagerEmpPerformance.java:159) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)

I have tried everything to fix it, even this Stack Overflow question: Null 'key' argument, but it did not help me solve the problem.

The coding for this graph to generate is:

PreparedStatement stmt = con.prepareStatement("select username, count(invoice_number) as invoiceCount, invoice_date from invoicedb where username = '" + empno + "' "
                    + "and extract(month from invoice_date) = '" + text + "' and extract(year from invoice_date) = '" + year + "'");
            ResultSet rs = stmt.executeQuery();
            DefaultCategoryDataset ddataset = new DefaultCategoryDataset();
            while (rs.next()) {
                ddataset.setValue(rs.getInt("invoiceCount"),
                       "invoiceCount",
                       rs.getString("username"));
            }
            stmt = con.prepareStatement("select username, count(quote_number) as quoteCount, quote_date from quotedb where username = '" + empno + "' and extract(month from quote_date) = '" + text + "'"
                    + " and extract(year from quote_date) = '"+ year +"'");
            rs = stmt.executeQuery();
            while (rs.next()) {
                ddataset.setValue(rs.getInt("quoteCount"),
                       "quoteCount",
                       rs.getString("username"));
            }

The error appears to lie on this line:

ddataset.setValue(rs.getInt("invoiceCount"),

Am I doing something wrong or is there another way to fix this error?

Upvotes: 0

Views: 1344

Answers (1)

JB Nizet
JB Nizet

Reputation: 691785

Thanks to the stack trace, I now know that you're calling the following method:

I can thus read its documentation and see that it says:

Parameters:

value - the value.
rowKey - the row key (null not permitted).
columnKey - the column key (null not permitted).

The message of the exception says:

java.lang.IllegalArgumentException: Null 'key' argument. at

We can thus safely assume that one of the arguments passed to the method (rowKey or columnKey) is null.

rowKey is the literal string "quoteCount". So it's obviously not null.

columnKey is rs.getString("username"). So that means that one of the rows returned by your query has a null username.

Fix your data, or filter out the rows that have a null username.

Upvotes: 3

Related Questions