我正在使用服务从数据库中检索数据。在DB中,我以字节的形式存储了图像,因为来自请求的响应是巨大的。无论如何,当我尝试获取值时,我得到一个错误,说417帧跳过,应用程序做了太多的工作。我在AsyncTask上运行整个请求,所以它在后台执行。我不知道为什么会发生错误。
该片段如下: -
private class NetworkCall extends AsyncTask<Void, Void, CharSequence>{
@Override
protected CharSequence doInBackground(Void... params) {
CharSequence seqResult = null;
try{
//http post request
HttpPost post = new HttpPost("http://localhost/HookService/SvcFiles/Hook.svc/GetAllUsers");
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
int p_iRadius = 20;
JSONStringer postParameters = new JSONStringer()
.object()
.key("p_iRadius").value(p_iRadius)
.endObject();
post.setEntity(new StringEntity(postParameters.toString()));
//get the response
HttpResponse response = client.execute(post);
// stream reader object
Reader resultReader = new InputStreamReader(response.getEntity().getContent());
//create a buffer to fill if from reader
char[] buffer = new char[(int) response.getEntity().getContentLength()];
//fill the buffer by the help of reader
resultReader.read(buffer);
//close the reader streams
resultReader.close();
seqResult = java.nio.CharBuffer.wrap(buffer);
}
catch (Exception e) {
Log.e("Web Service Error", "Web Service error", e);
}
return seqResult;
}
@Override
protected void onPostExecute(CharSequence Result){
JSONArray resultArray = null;
try{
JSONObject jsonObject = new JSONObject(Result.toString());
resultArray = jsonObject.getJSONArray("ReturnModel");
//resultArray = new JSONArray(Result.toString());
}catch(Exception e){
Log.e("Json error", "Json error", e);
}
GsonBuilder gsonb = new GsonBuilder();
DateDeserializer ds = new DateDeserializer();
gsonb.registerTypeAdapter(Date.class, ds);
Gson gson = gsonb.create();
Type datasetListType = new TypeToken<Collection<MapPushPinData>>() {}.getType();
try{
mapUserList = gson.fromJson(resultArray.toString(), datasetListType);
}
catch (Exception e){
Log.e("Serialization Error", "Error", e);
}
setUpMapIfNeeded();
}
}
基本上我获取凭据在地图上用小图像和名称绘制标记。当请求发出时,跳过帧,因为没有绘制标记。
此外,我在模拟器上运行它,我无法在设备上测试它,因为我的设备无法包含在同一网络中。