cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle java null pointer exceptions

Highlighted
Visitor

How to handle java null pointer exceptions

Hey There,

I was working on this very simple service that I wrote for ThingShapes.

All I am doing is "Updating a Thing's Property". However, I keep getting java.lang.NullPointerException Cause: Null,

my Service on the Thing is following:

if(Contact){

Things[uuid].Contact = Contact;

}

if(Contact_Phone){

Things[uuid].Contact_Phone = Contact_Phone;

}

if(MyName){

Things[uuid].MyName = MyName;

}

if(phyLocation){

Things[uuid].phyLocation = phyLocation;

}

if(freq){

Things[uuid].freq = freq;

}

I am not sure what I am doing wrong.

Tags (1)
9 REPLIES 9

Re: How to handle java null pointer exceptions

Without looking at your code first, what are the input and output types specified for the service?

Re: How to handle java null pointer exceptions

No Outputs, all string inputs

Re: How to handle java null pointer exceptions

you can put few console.log() to check if any prop values are getting as null.

Also you can check the spell of Propery names if those are correct.

Re: How to handle java null pointer exceptions

Hi mustafa bereket​,

This service works fine for me. Which ThingWorx version you are on?

Please check Application logs for more details.

Points to check:

1. Make sure the Thing where service is being tested is saved.

2. Make Sure uuid is given a correct ThingName.

3. User has Visibility/RunTime Permissions to the Thing.

Are you able to run any service on this Thing? Also, try restarting your Tomcat once to avoid any caching issue.

Application/Script logs will give better insight on the issue.

I hop it helps.

Re: How to handle java null pointer exceptions

Try putting a space after the "if"s.

Re: How to handle java null pointer exceptions

I've actually just tried running your service and it works. Could you please export your entity and email it to me to posipova@ptc.com ? I will check to see if everything was saved/declared properly.

Re: How to handle java null pointer exceptions

I tried putting logs. but that Null Pointer problem appearntly comes up before my log outputs. So, I can see nothing but that Null Exception in the logs.

Re: How to handle java null pointer exceptions

Tried but didn't change the result.

Re: How to handle java null pointer exceptions

Hi, to catch the error, can you try to wrap your code with:

try {

...your code...

}

catch (e) {

     logger.debug("Line " + e.lineNumber + ": " + e);

}