double cell value

Hi,

I guess, the solution is rather easy but I don't get the problem...

My node throws an error when it tries to read the double value of a double cell. As I also allow to process int cells, the statement I've use looks like this:

DataCell valueCell = row.getCell(colIdx);
Double value = null;
if (!valueCell.isMissing()) value = ((IntCell) valueCell).getDoubleValue();

If I debug the code in IntelliJ and evaluate the expression I don't get any error...

The error I get in KNIME is this one:

ERROR     BinningAnalysis     Execute failed: org.knime.core.data.def.DoubleCell cannot be cast to org.knime.core.data.def.IntCell
DEBUG     BinningAnalysis     Execute failed: org.knime.core.data.def.DoubleCell cannot be cast to org.knime.core.data.def.IntCell
java.lang.ClassCastException: org.knime.core.data.def.DoubleCell cannot be cast to org.knime.core.data.def.IntCell
    at de.mpicbg.tds.knime.hcstools.populationanalysis.BinningAnalysisNodeModel.execute(BinningAnalysisNodeModel.java:125)
    at org.knime.core.node.NodeModel.execute(NodeModel.java:668)
    at org.knime.core.node.NodeModel.executeModel(NodeModel.java:524)
    at org.knime.core.node.Node.execute(Node.java:873)
    at org.knime.core.node.workflow.SingleNodeContainer.performExecuteNode(SingleNodeContainer.java:845)
    at org.knime.core.node.exec.LocalNodeExecutionJob.mainExecute(LocalNodeExecutionJob.java:100)
    at org.knime.core.node.workflow.NodeExecutionJob.run(NodeExecutionJob.java:166)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.knime.core.util.ThreadPool$MyFuture.run(ThreadPool.java:124)
    at org.knime.core.util.ThreadPool$Worker.run(ThreadPool.java:239)

What is wrong with my code?

you're using intCells instead of doublecells should be:
if (!valueCell.isMissing()) value = ((DoubleCell) valueCell).getDoubleValue();

btw, it would anyway be better to convert to doublevalue, which than works for ints and doubles.


if (!valueCell.isMissing()) value = ((DoubleValue) valueCell).getDoubleValue();

Thanks a lot for the second hint (I had to compare it three times with the upper line to get the difference that I need to cast to DoubleValue instead of DoubleCell).

I was probably mislead because of the method getDoubleValue() from class IntCell.

That's exaclty what I need as I don't care whether the numeric value comes from an int cell or a double cell.