How to handle java null pointer exceptions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Labels:
-
Extensions
-
Install-Upgrade
- Tags:
- java
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Without looking at your code first, what are the input and output types specified for the service?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
No Outputs, all string inputs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi, to catch the error, can you try to wrap your code with:
try {
...your code...
}
catch (e) {
logger.debug("Line " + e.lineNumber + ": " + e);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Try putting a space after the "if"s.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Tried but didn't change the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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.
