Protected StringDoinbackground(String...URLs) {
Stringwr.=URLs[0];
StringResult= "";
HttpResponseResponse=Doresponse(wr.);
If (Response== Null) {
ReturnResult;
} Else {
Try {
Result=Inputstreamtostring(Response.GetEntity().GetContent());
} Catch (IllegalStateExceptionE) {
Log.E(TAG,E.Getlocalizedmessage(),E);
} Catch (IOExceptionE) {
& nbsp log. (tag, E. Getlocalizedmessage E }
& nbsp }
return Result; }
I want to send the data to Dadabase.here below I enclose my remaining codes.so please check and clear my problem.please
Private HttpResponseDoresponse(Stringwr.) {
HttpClientHttpClient= New Defaulthttpclient(Gethttpparams());
HttpResponseResponse= Null;
Try {
Switch (TaskType) {
CasePost_task:
HttpPostHttpPost= New HttpPost(wr.);
ADD parameters
HttpPost.Setentity(New Urlencodedformentity(Params));
Response=HttpClient.Execute(HttpPost);
Break;
CaseGet_task:
HttpGetHttpGet= New HttpGet(wr.);
Response=HttpClient.Execute(HttpGet);
Break;
}
} Catch (ExceptionE) {
Log.E(TAG,E.Getlocalizedmessage(),E);
}
ReturnResponse;
}
Private StringInputstreamtostring(InputStream Is) {
StringLine= "";
StringBuilderTotal= New StringBuilder();
Wrap a bufferedreader around the InputStream
BufferedReaderRd= New BufferedReader(New InputStreamReader(Is));
Try {
Read response until the end
While ((Line=Rd.ReadLine()) != Null) {
Total.Append(Line);
}
} Catch (IOExceptionE) {
log e (tag, E getlocalizedmessage (), E); }
& nbsp //Return full String
return Total. }
I get NullPointerException
in the line below,
result = inputStreamToString(response.getEntity().getContent());
.
I don't understand about entity
and content.anyone can help me??
Workaround 1:
Your HTTP response has not been completed entity
. That's why it's getEntity()
returned null
.
The JavaDoc of GetEntity () indicates that a null
value can be returned. Therefore, you should always check the.
For example, instead of:
result = inputStreamToString(response.getEntity().getContent());
You can do this:
Final HttpentityEntity=Response.GetEntity();
If (Entity== Null) {
Log.w (tag, "the response has no entity."
// note:this method would return "" in the case, so we mu The St check for so in OnPostExecute ().
//do whatever are necessary here ...
} else {
result = inputstreamtostring (entity. Getcontent
} /span>
I get an HTTP response, but response.getentity (). GetContent () displays a null pointer exception