List Files & Java Snippet: Pass file location


#1

Hi all,

in the output table of my List Files node I get a column named Location containing the absolute path of the read files (e.g. “C:\folder\image.jpg”).

My next node is a Java Snippet. Here I would like to create a File object (java.io.File) based on column Location from the previous node (= c_Location):
File file = new File(c_Location);
Unfortunatly this results in an error message, when I run the Java Snippet:

ERROR Java Snippet 0:3 Execute failed: java.lang.NullPointerException

Now I tried to write the file path directly in the Java Snippet, rather than injecting it from the input of the previous node:
File file = new File("C:\\folder\\image.jpg");
This works great. No NullPointerException.

But how can I realize the first approach using the input variable c_Location correctly?

Thanks for your help in advance.

Best regards

Dan


#2

By the way this syntax also works fine:
File file = new File("C:/folder/image.jpg");

But File file = new File(c_Location); still does not work :frowning_face:

Does the Java Type of the inputs play a role?
String vs. String (toString())


#3

Hi @online-dan,

Unfortunately, I can’t reproduce this issue. Does 11776.knwf (5.7 KB) generate the same error for you?

Also, could you please report which version of KNIME Analytics Platform and which operating system you are running? In general, please provide as much information as possible according to our Bug Reporting Best Practices.

Best,
Stefan