Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Talend_ent
Contributor III
Contributor III

Data_Type converstion Error

Hi all,

I'm trying to convert integer column to string getting "java. lang.NumberFormatException: For input string:"

my input integer column is as follows

1234

4467

4646

opt:

1234

4467

4646

I tried with Integer.toString(row1.emp_num) it throwing Number format exception.

Any suggestions would be helpful

Thanks and Regards,

Talend_ent.

Labels (3)
14 Replies
Talend_ent
Contributor III
Contributor III
Author

The input column contains leading spaces.

gjeremy1617088143

Hi, have you tried String.valueOf(row1.emp_num) ?

Send me Love and kudos

Talend_ent
Contributor III
Contributor III
Author

@guenneguez jeremy​ yes, I tried with String.ValueOf() getting same error.

 

gjeremy1617088143

with wich component do you read data ?

what is your data source (csv ,database,xml...)?

are you succeed in reading it as number ?

if it's csv for example just change the type of your column in the schema to string in tfileinputdelimited component

 

Talend_ent
Contributor III
Contributor III
Author

@guenneguez jeremy​  my source is xml and I changed the datatype as a string it is working fine .

 

when I using datatype converstion in tMap getting null pointer exception here is my tmap expression

 

row1.emp_num.equals(null)||row1.emp_num==null?null:Integer.parseInt(row1.emp_num.trim());

 

any workaround.

gjeremy1617088143

(row1.emp_num!=null && !row1.emp_num.equals("null"))?Integer.parseInt(row1.emp_num.trim()):null

 

or

 

(row1.emp_num!=null && !(row1.emp_num.replaceAll("\\D")).equals("") )?Integer.parseInt(row1.emp_num.trim()):null

 

for the second one i test null value then i look if when i delete all non digit char there is an empty value or not

Talend_ent
Contributor III
Contributor III
Author

For the first expression it throwing null pointer exception. coming to the second one in replaceall method you're using single argument instead of two.

 

attachment shows the error for second expression.0695b00000H83bnAAB.png

gjeremy1617088143

sorry my fault :

(row1.emp_num!=null && !(row1.emp_num.replaceAll("\\D","")).equals("") )?Integer.parseInt(row1.emp_num.trim()):null

Talend_ent
Contributor III
Contributor III
Author

Again i'm getting java.lang.NullPointerException.