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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to handle java null pointer exceptions

mbereket
3-Newcomer

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.

9 REPLIES 9
posipova
20-Turquoise
(To:mbereket)

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

mbereket
3-Newcomer
(To:posipova)

No Outputs, all string inputs

Rajesh_A
2-Explorer
(To:mbereket)

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.

mbereket
3-Newcomer
(To:Rajesh_A)

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.

qngo
12-Amethyst
(To:Rajesh_A)

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

try {

...your code...

}

catch (e) {

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

}

ankigupta
12-Amethyst
(To:mbereket)

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.

posipova
20-Turquoise
(To:mbereket)

Try putting a space after the "if"s.

mbereket
3-Newcomer
(To:posipova)

Tried but didn't change the result.

posipova
20-Turquoise
(To:mbereket)

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.

Announcements


Top Tags