Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all!
I have been trying to trim an entry in a table but I keep getting the following error:
Cannot invoke "String.substring(int,int)" because "row.A" is null
The way I did it:
In tmap I tried to check first if the entry is empty and then do the trimming like the following
row.A == null ? row.A : (row.A.length() >10 ? StringHandling.LEFT(row.A,4):row.A)
It is not working. Any suggestions from your side?
Thank you!
This is caused by the logic here.....
((row3.newColumn1== null) || ("".equals(row3.newColumn1 )) || row3.newColumn1.isEmpty()) ? (row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.newColumn1,7): row3.newColumn1) : row3.newColumn1
This is saying....
IF row3.newColumn1 is null OR row3.newColumn1 is an empty String OR row3.newColumn1 is empty THEN
IF row3.newColumn1 is longer than 7 characters THEN .... do the rest.
If row3.newColumn1 is null you are allowing the code to attempt to use the length() method on a null object. This is not possible.
I think you need.....
((row3.newColumn1== null) || ("".equals(row3.newColumn1 )) || row3.newColumn1.isEmpty()) ? row3.newColumn1 : row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.newColumn1,7): row3.newColumn1
What do you get when you run your code where you check for null?
I only get the error message as written above.
I thought I am checking für null by
row.A == null ? row.A : (row.A.length() >10 ? StringHandling.LEFT(row.A,4):row.A)
That code should work. Can you post the exact error message you get? This could be related to another column.
Exception in component tMap_3 (Trim)
java.lang.NullPointerException: Cannot invoke "String.length()" because "row.A" is null
at project_1.trim_0_1.Trim.tFileInputExcel_3Process(Trim.java:1967)
at project_1.trim_0_1.Trim.runJobInTOS(Trim.java:2555)
at project_1.trim_0_1.Trim.main(Trim.java:2393)
Can you show me a screenshot of your tMap configuration please? I'll need to see every output expression.
Hi
here is the screenshot for this error message ( column A type: string)
Exception in component tMap_3 (test_TrimSTring)
java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because "row3.A" is null
at project_1.test_trimstring_0_1.test_TrimSTring.tFileInputExcel_3Process(test_TrimSTring.java:1588)
at project_1.test_trimstring_0_1.test_TrimSTring.runJobInTOS(test_TrimSTring.java:2042)
at project_1.test_trimstring_0_1.test_TrimSTring.main(test_TrimSTring.java:1880)
I also tried
(row3.A== null) || ("".equals(row3.A)) || row3.A.isEmpty() ? row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.A,7): row3.A : row3.A
and with brackets
((row3.A== null) || ("".equals(row3.A)) || row3.A.isEmpty() )? (row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.A,7): row3.A 😞 row3.A
Error message:
Exception in component tMap_3 (test_TrimSTring)
java.lang.NullPointerException: Cannot invoke "String.substring(int, int)" because "row3.A" is null
at project_1.test_trimstring_0_1.test_TrimSTring.tFileInputExcel_3Process(test_TrimSTring.java:1588)
at project_1.test_trimstring_0_1.test_TrimSTring.runJobInTOS(test_TrimSTring.java:2042)
at project_1.test_trimstring_0_1.test_TrimSTring.main(test_TrimSTring.java:1880)
You have at least 2 other tMap Var expressions using the column row3.A without a check for null. I believe that is your problem here.
Hi
thanks for the tipp.
It still doesnt work properly: It works for row3.newColumn but eg not for row3.newColumn4 or row3.newColumn7. I have no idea why.
in tmap:
((row3.newColumn1== null) || ("".equals(row3.newColumn1 )) || row3.newColumn1.isEmpty()) ? (row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.newColumn1,7): row3.newColumn1) : row3.newColumn1
Error:
Exception in component tMap_3 (B_TrimSTring)
java.lang.NullPointerException: Cannot invoke "String.length()" because "row3.newColumn1" is null)
This is caused by the logic here.....
((row3.newColumn1== null) || ("".equals(row3.newColumn1 )) || row3.newColumn1.isEmpty()) ? (row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.newColumn1,7): row3.newColumn1) : row3.newColumn1
This is saying....
IF row3.newColumn1 is null OR row3.newColumn1 is an empty String OR row3.newColumn1 is empty THEN
IF row3.newColumn1 is longer than 7 characters THEN .... do the rest.
If row3.newColumn1 is null you are allowing the code to attempt to use the length() method on a null object. This is not possible.
I think you need.....
((row3.newColumn1== null) || ("".equals(row3.newColumn1 )) || row3.newColumn1.isEmpty()) ? row3.newColumn1 : row3.newColumn1.length()>7 ? StringHandling.LEFT(row3.newColumn1,7): row3.newColumn1