Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot invoke "String.replaceAll(String, String)" because row is null

I am getting an error message in Talend and it appears to be down to a having a ‘NULL’ value within my ‘comments’ field.

I currently have this expression row1.comments.replaceAll("\u0000", "") which has been working and the reason for having this in place is because I have some text which is spaced out (example T E S T).

However,the latest run has failed due to a ‘NULL’ appearing in the comments field and I don’t think my job design knows how to handle this, as well as the removing the spaces from the ‘comments’ text.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

This is the error message:
Exception in component tMap_1 (FACT_test)

java.lang.NullPointerException: Cannot invoke "String.replaceAll(String, String)" because "row1.comments" is null

Is there anyway to get around this problem, please?

>Solution :

There’s a little bit of information missing from your question (like what component are you using?) but regardless, you can check for null and deal with it accordingly using a ternary operator, something like this should work …

row1.comments == null ? "" : row1.comments.replaceAll("\u0000", "")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading