Trouble with NullPointerException during job run

One Star

Trouble with NullPointerException during job run

Hi,
I'm having trouble getting my job to complete. During the middle of the job run, I appear to hit a nullpointer exception. I appear to successfully complete a lookup from one of my database tables, but when I try to use that data and data from a delimited file I have loaded, it catches the null pointer and quits before successfully uploading the data to my database.
Below is the output code when I try to run the program:
----------------------------------------------------------------------------------------------
Starting job Transaction_Processing at 13:08 04/06/2012.
connecting to socket on port 4079
connected
Exception in component tMap_1_TMAP_IN
java.lang.NullPointerException
at bonusme.transaction_processing_0_1.Transaction_Processing.tFileList_1Process(Transaction_Processing.java:3461)
at bonusme.transaction_processing_0_1.Transaction_Processing.tMysqlConnection_1Process(Transaction_Processing.java:522)
at bonusme.transaction_processing_0_1.Transaction_Processing.runJobInTOS(Transaction_Processing.java:7970)
at bonusme.transaction_processing_0_1.Transaction_Processing.main(Transaction_Processing.java:7831)
disconnected
Job Transaction_Processing ended at 13:08 04/06/2012.
----------------------------------------------------------------------------------------------
Any ideas on how to resolve this issue? Thanks for the help.
- Mike
One Star

Re: Trouble with NullPointerException during job run

Hi Mike
Could you upload a screenshot of tMap?
I guess there are some expressions in it which causes NPE exception.
Regards,
Pedro
One Star

Re: Trouble with NullPointerException during job run

Hi,
Here is a screenshot of most of my tmap. I have two output tables. One that take the inner join successes and one that takes the inner join rejects. I don't need to fill each of the columns though. Some will simply be loaded into the database as a blank.
Let me know what you think I should do to resolve the null pointer.

Thanks,
Mike
One Star

Re: Trouble with NullPointerException during job run

Mike,
If you click the code window tab (bottom left of the Job design window), you can go to line 3461 and see what field is actually causing the error. If the line shown doesn't make sense, check the other line numbers referenced in the error.
I can't see your entire tMap, but the Long.valueOf(row1.CardNumber) seems like a likely candidate. If CardNumber is null, Long.valueOf will throw an NPE.
You could also look for places where you are using row1someField.equals("ABC"). It is safer to use "ABC".equals(row1.someField) because in this case, "ABC" is a fixed value that will never be null.
Thanks,
Ben
One Star

Re: Trouble with NullPointerException during job run

Hi,
thanks for the suggestion. It appears that it is taking offense this code block:
Var.Points = (java.lang.Math.round(row1.TransactionAmount))* row1.Multiplier;
The actual line of code that is throwing it appears to be the rounding step. Do I just have to write some code to check if that input is null before performing the operation?
- Mike
One Star

Re: Trouble with NullPointerException during job run

You know, I think the problem is that occasionally there is no value in the multiplier field. So it tries to multiply by that and throws the null pointer.
How would I go about inserting code to check whether or not the multiplier value is null/empty?
I know it should be something like
if row1.Multiplier == null
(do rounding without multiplying)
else
(do rounding and multiplying)
but I don't know where to actually put this logic in with the program. Can I do this sort of if/else statement in the expression editor?
- Mike
One Star

Re: Trouble with NullPointerException during job run

More than likely, the problem is a null TransactionAmount, not the Multiplier.
(java.lang.Math.round(row1.TransactionAmount))* row1.Multiplier;
The if format for a Talend expression is
(condition)?val_if_true:val_if_false
example
null == row1.TransactionAmount? null : (java.lang.Math.round(row1.TransactionAmount))* row1.Multiplier