Null pointer exception in tjava

Highlighted
Four Stars

Null pointer exception in tjava

Dear Experts,

 

I am very new to Talend.

 

I am getting the below error while executing a talend job which transfers data from oracle database to json.

 

the intial design was,

tdbinput ---> tmap ---> twritejsonfields

since I got int to String type mismatch error, I have introduced tjava component and converted the column to string. jobdesign_talend.pngmapping_talend.png

tjava_talend.png

json.png

The job execution is failing now with the below error.

Please help me in resolving.

 

Starting job JOB_PT_ORA_TO_JSON_LOCATION_INFO at 11:00 06/06/2019.

[statistics] connecting to socket on port 3883
[statistics] connected
Exception in component tJava_1 (JOB_PT_ORA_TO_JSON_LOCATION_INFO)
java.lang.NullPointerException
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.tDBInput_2Process(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:3046)
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.runJobInTOS(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:6606)
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.main(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:6432)
[FATAL]: etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO - tJava_1 null
java.lang.NullPointerException
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.tDBInput_2Process(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:3046)
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.runJobInTOS(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:6606)
 at etl_poc_v2.job_pt_ora_to_json_location_info_0_1.JOB_PT_ORA_TO_JSON_LOCATION_INFO.main(JOB_PT_ORA_TO_JSON_LOCATION_INFO.java:6432)
[statistics] disconnected

Job JOB_PT_ORA_TO_JSON_LOCATION_INFO ended at 11:00 06/06/2019. [exit code=1]

 

Thanks in Advance!

Best Regards,

Priya


Accepted Solutions
Nine Stars

Re: Null pointer exception in tjava

Default values are not supported in tMap in 6.2 it looks like:

https://help.talend.com/reader/I5~nujSNXadpT4WYWRHrjw/NnnMrtkRENP9mpQw6MrDHA

They may be supported now, I am not sure.  You could test it by using a default like "x" for a String field.

 

You could also try quoting the default value for your BigDecimal, like "1".

 

You can implement your default values in the row expression:

 

row1.AVP_STANDARD_ALGORITHM != null ? row1.AVP_STANDARD_ALGORITHM : new BigDecimal("1")

 

 

--
Please give Kudos and mark topics as solved where appropriate.

All Replies
Nine Stars

Re: Null pointer exception in tjava

Are you new to Java?  If not, you can debug this kind of error by looking at the 'Code' tab and finding the line with the red error.  You can inspect the generated Java code there.

 

You should really use a tJavaRow here.  Either way, both tJava and tJavaRow do not pass the variables onto the next component.  So all values will be null at your tWriteJSONField component.

 

I am not sure where or why you got an int to String type mismatch error.  You don't need a Java component there, you can do the conversion of the BigDecimal to a String in your tMap.  In the AVP_STANDARD_ALGORITHM column in out_map, make it a String type and put row1.AVP_STANDARD_ALGORITHM.toString()  as the expression.  Propagate the type change down the line.

 

Also, the code in your tJava does nothing.  You are not assigning the result to a variable.  It does not convert inline like that.

 

 

 

 

--
Please give Kudos and mark topics as solved where appropriate.
Four Stars

Re: Null pointer exception in tjava

@nfz11 thanks a ton for your reply. I have modified my job. I have removed the tjava component. I am getting type mismatch int to string converstion error after mapping tmap --> tjsonwritefield.

 

row1.AVP_STANDARD_ALGORITHM.toString() -> is also not converting in tmap.

 

please help me in resolving the issue.

 

Error in the component's properties:Type mismatch: cannot convert from int to String

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ((tjsonout.MANIPULATE_EVENTS != null) ? tjsonout.MANIPULATE_EVENTS.toPlainString() : 0))

Type mismatch: cannot convert from int to String

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ((tjsonout.MANUALLY_INSERTED_PARTS != null) ? tjsonout.MANUALLY_INSERTED_PARTS.toPlainString() : 0))

Type mismatch: cannot convert from int to String

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ((tjsonout.AVP_STANDARD_ALGORITHM != null) ? tjsonout.AVP_STANDARD_ALGORITHM.toPlainString() : 1))

Type mismatch: cannot convert from int to String

The method put(String, String) in the type Map<String,String> is not applicable for the arguments (String, ((tjsonout.DISABLED != null) ? tjsonout.DISABLED.toPlainString() : 0))

 

Best Regards,

Priya

Four Stars

Re: Null pointer exception in tjava

tostring.png here is my tmap screenshot with toString(). the direct mapping without any conversion is running fine if I directly load the data to Database. I am getting conversion error only when mapping to tjsonwritefileld component.

 

Please let me know your comments.

 

Best Regards,

Priya

Nine Stars

Re: Null pointer exception in tjava

You need to change the type to String for those columns such as AVP_STANDARD_ALGORITHM in the schema editor of out_tmap in the lower right of the map editor.  Right now they are still BigDecimal.

--
Please give Kudos and mark topics as solved where appropriate.
Four Stars

Re: Null pointer exception in tjava

@nfz11 yes I tried changing the output column also as String. Eventhough it is failing with same error.

 

I suspect something needs to be changed in TJSONWRITEFILED component. please let me know whether I should create as attribute for bigdecimal datatype columns. here I have created as add subelement like we keep for String.

 

json.pngBest Regards,

Priya

Nine Stars

Re: Null pointer exception in tjava

You can write it as a sub-element as well. Did you also change the input column to string in write json field?

You can put a tlogrow before the json component to see exactly what data is coming out of the tmap and going to the json writer.

You can remove all of the fields from your json writer and then add them back one by one until you get the error to see which field is causing it.
--
Please give Kudos and mark topics as solved where appropriate.
Four Stars

Re: Null pointer exception in tjava

@nfz11 as you suggested I tried adding column by column and checked, I faced issues in 4 columns which has some default values in tmap. if I remove the default value for the columns it is working fine.

jsonissue.png

what needs to be done if we should to keep default values also and run without facing int to string error.

 

Best Regards,

Priya

Nine Stars

Re: Null pointer exception in tjava

Default values are not supported in tMap in 6.2 it looks like:

https://help.talend.com/reader/I5~nujSNXadpT4WYWRHrjw/NnnMrtkRENP9mpQw6MrDHA

They may be supported now, I am not sure.  You could test it by using a default like "x" for a String field.

 

You could also try quoting the default value for your BigDecimal, like "1".

 

You can implement your default values in the row expression:

 

row1.AVP_STANDARD_ALGORITHM != null ? row1.AVP_STANDARD_ALGORITHM : new BigDecimal("1")

 

 

--
Please give Kudos and mark topics as solved where appropriate.

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog