java 空“键”参数错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3447108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:54:15  来源:igfitidea点击:

Null 'key' argument error

javachartsjasper-reportsireport

提问by Halo

I'm using IReport 3.5.0 and my java GWT application uses the compiled .jasper file, to create a report. I'm creating the datasource in the java application and use fillReport()method to fill the report. It works fine, it fills the fields that I have defined both in the .jrxml and Java application.

我使用的是 IReport 3.5.0,我的 java GWT 应用程序使用编译后的 .jasper 文件来创建报告。我正在 java 应用程序中创建数据源并使用fillReport()方法来填写报告。它工作正常,它填充了我在 .jrxml 和 Java 应用程序中定义的字段。

However, I want to use those fields to create a pie chart, and it doesn't work. I give my working fields as key and value expressions for the chart, but when I run the application, it gives the error java.lang.IllegalArgumentException: Null 'key' argument.I couldn't solve it, even when I give $V{PAGE_COUNT}as key expression, it always give the same 'null key' error. I'm stuck. Thanks for any help.

但是,我想使用这些字段来创建饼图,但它不起作用。我将我的工作字段作为图表的键和值表达式,但是当我运行应用程序时,它给出了java.lang.IllegalArgumentException: Null 'key' argument.我无法解决的错误,即使我$V{PAGE_COUNT}作为键表达式给出,它也总是给出相同的“空键”错误. 我被困住了。谢谢你的帮助。

回答by Thierry-Dimitri Roy

I had the same kind of issue. Basically the Pie Chart in JasperReport hates null object. The error message doesn't help very much...

我有同样的问题。基本上 JasperReport 中的饼图讨厌空对象。错误消息并没有多大帮助...

Since you have already check for the key expression, check every other elements. My error was in a label expression!

由于您已经检查了关键表达式,因此请检查所有其他元素。我的错误在于标签表达式!

If you can run your application in a IDE, put a breakpoint on "IllegalArgumentException". It will help you find the root cause. Also make sure the report recompile the jrxml every time you make a change.

如果您可以在 IDE 中运行您的应用程序,请在“IllegalArgumentException”上放置一个断点。它将帮助您找到根本原因。还要确保每次进行更改时报告都会重新编译 jrxml。

Another approach would be to start with an example and modify it to fit your need little by little. You will find the culprit soon enough!

另一种方法是从一个例子开始,然后一点一点地修改它以满足您的需要。你很快就会找到罪魁祸首!

By the way, this has nothing to do with GWT since this all run on the server.

顺便说一下,这与 GWT 无关,因为这一切都在服务器上运行。

回答by jlago

I had the same kind of problem with iReport 3.0 I used conditionals to work with null values on key expression and value expression:

我在 iReport 3.0 中遇到了同样的问题,我使用条件来处理键表达式和值表达式的空值:

($F{FIELDEXPRESSION}!=null?$F{FIELDEXPRESSION}:"")

($F{FIELDVALUE}!=null?(new BigDecimal($F{FIELDVALUE})):(new BigDecimal("0")))

回答by PallaviBatra

I had the same problem. So used a if loop to check if there is a null value in the column i am traversing.

我有同样的问题。所以使用 if 循环来检查我正在遍历的列中是否有空值。

  if(result.get()==null) // result is where is stored my resultset output
 {
    dataset.setValue(count.get(j),"N/A","No Data Available");} // count refers to the number of null entries
       else dataset.setValue(count.get(j),results.get(j),results.get(j)); 
   }

回答by kiran reddy

Since I am unable to comment, this might not be a full resolution. I resolved my issue by checking the data types of the fields.

由于我无法发表评论,这可能不是一个完整的解决方案。我通过检查字段的数据类型解决了我的问题。

Where I previously had:

我以前有过的地方:

<field name="date" class="java.sql.Date"/>

I changed to:

我改为:

<field name="date" class="java.lang.String"/>

because my field will give me ex:"Jul 15" (FYI which I made it in my query) format type date which can't be java.sql.Datetype.

因为我的字段会给我 ex:"Jul 15" (FYI,我在我的查询中做的) 不能java.sql.Date输入的格式类型日期。