You need to sign in to do that
Don't have an account?

JSON content display : Attempt to de-reference a null object
Hello,
I am trying to display content from a JSON feed on my Salesforce page using APEX/visualforce page. From information gathered, I am able to get the details of the JSON on variable. But when running the visualforce page, I get the below error. Any help much appreciated..
Apex Code
Visual force page :
Error that I get when runnig the page is
I am trying to display content from a JSON feed on my Salesforce page using APEX/visualforce page. From information gathered, I am able to get the details of the JSON on variable. But when running the visualforce page, I get the below error. Any help much appreciated..
Apex Code
global class loraGeneralEventsController { public String title{get;set;} public String link{get;set;} public String event_date{get;set;} public location location{get;set;} public List<Items> dr{get;set;} public loraGeneralEventsController(){ } public void requestM(){ String url = 'https://www.semtech.com/company/events-json/lora-general-event'; HttpRequest req = new HttpRequest(); req.setEndpoint(url); req.setMethod('GET'); Http http = new Http(); HttpResponse res = http.send(req); String responseBody = res.getBody(); system.debug('JSON Content : ' + responseBody); ResCls resItem = (ResCls)JSON.deserialize(responseBody, ResCls.class); List<Items> rl = resItem.items; system.debug('Item List : ' + resItem.items); dr = new List<Items>(); for(Items it:rl){ system.debug('Item Name: ' + it); title = it.title; link = it.link; system.debug('event_date: ' + it.event_date); system.debug('location: ' + it.location); dr.add(it); } system.debug('List: ' + dr); } public class ResCls{ List<Items> items; } public class Items{ public String title {get;set;} public String link {get;set;} public String event_date {get;set;} public String description {get;set;} public String location {get;set;} public String categories {get;set;} public String pubdate {get;set;} } }
Visual force page :
<apex:page Controller="loraGeneralEventsController" action="{!requestM}" sidebar="false"> <apex:pageBlock> <apex:pageblockSection > <apex:pageblockTable value="{!dr}" var="dd"> <apex:column headerValue="Title"><apex:outputText value="{!dd.title}"/></apex:column> <apex:column headerValue="URL"><apex:outputText value="{!dd.link}"/></apex:column> <apex:column headerValue="Date"><apex:outputText value="{!dd.event_date}"/></apex:column> <apex:column headerValue="Location"><apex:outputText value="{!dd.location}"/></apex:column> </apex:pageblockTable> </apex:pageblockSection> </apex:pageBlock> </apex:page>
Error that I get when runnig the page is
Attempt to de-reference a null object Error is in expression '{!requestM}' in component <apex:page> in page lorageneralevents: Class.loraGeneralEventsController.requestM: line 30, column 1 An unexpected error has occurred. Your development organization has been notified.
All Answers