I am getting attempt to de-reference null object error the below callouts.
class1:
public class ProcessImgCallout {
@future (callout=true)
public static void SendImage(ID id) {
system.debug('hello Mahesh '+id);
String endPointURL = 'https://cloud.ocrsdk.com/processBusinessCard?exportformat=xml';
String userName = '';// i removed username for security puropse
String password = '';//i removed password for security puropse
ContentVersion co = [Select id,pathOnClient,title,versionData from ContentVersion where id =:id];
Blob img =co.versionData;
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
Httprequest request = new HttpRequest();
Http http = new Http();
request.setMethod('POST');
request.setEndpoint(endPointURL);
request.setHeader('Authorization', authorizationHeader);
request.setHeader('Content-Type', 'image/jpeg');
request.setTimeout(2 * 60 * 1000);
request.setBodyAsBlob(img);
HttpResponse res = http.send(request);
System.debug('responseBody: '+res.getBody());
Dom.Document docx = new Dom.Document();
//docx.load(responseUrl2);
system.debug('@@@'+res.getbody());
docx.load(res.getbody());
//system.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '+doc);
String taskId = docx.getRootElement().getChildElement('task', null).getAttribute('id', null);
system.debug(taskId);
gettaskStatus.GetStatus(taskId);
}
}
Class2:
public class gettaskStatus {
public static void GetStatus(String id){
system.debug('hello mahesh i am with task id to get status'+id);
//String taskid=id;
String endPointURL = 'http://cloud.ocrsdk.com/getTaskStatus?taskId='+id;
system.debug(endPointURL);
String userName = '';//i removed username for security puropse
String password = '';//i removed password for security puropse
Blob headerValue = Blob.valueOf(userName + ':' + password);
String authorizationHeader = 'BASIC ' +
EncodingUtil.base64Encode(headerValue);
Httprequest req = new HttpRequest();
Http ht = new Http();
req.setMethod('GET');
req.setEndpoint(endPointURL);
req.setHeader('Authorization', authorizationHeader);
req.setTimeout(2 * 60 * 1000);
//req.setHeader('Content-Type', 'image/jpeg');
HttpResponse resp = ht.send(req);
System.debug('responseBody: to download url '+resp.getBody());
Dom.Document doc = new Dom.Document();
//docx.load(responseUrl2);
system.debug('@@@'+resp.getbody());
doc.load(resp.getbody());
//system.debug('$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ '+doc);
String resulturl = doc.getRootElement().getChildElement('task', null).getAttribute('resultUrl', null);
system.debug(resulturl);
GetLeadfromUrl.GetDownloadUrl(resulturl);
}
}
I am getting attempt to de-reference null object error in the second class can anyone please help me , how to fix this?
public class GetLeadfromUrl {
public static void GetDownloadUrl(String url) {
String ROOT_TAG = 'ocrsdk.com/schema/recognizedBusinessCard-1.0.xsd';;
// system.debug(url);
String downloadurl=url;
String newUrl=downloadurl.remove('amp;');
system.debug(newUrl);
String endPointURL =newUrl;
// ??
}
}
Class.GetLeadfromUrl.GetDownloadUrl: line 7, column 1 Class.gettaskStatus.GetStatus: line 37, column 1 Class.ProcessImgCallout.SendImage: line 39, column 1 16:10:36.526 (526290597)|CUMULATIVE_LIMIT_USAGE 16:10:36.526 (526290597)|LIMIT_USAGE_FOR_NS|(default)|
– Mahesh Jun 12 '17 at 10:50