您好我正在尝试从我的 MVC asp.net 获取一个 json 对象。
我收到一个错误
StringBuilder url = new StringBuilder(URL);
HttpGet get = new HttpGet (url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if(status == 200)
{
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray timeline = new JSONArray(data);
JSONObject last = timeline.getJSONObject(0);
return last;
}
else
{
Toast.makeText(Authenticate.this, "error", Toast.LENGTH_LONG);
return null;
}
错误:
Java.IO 异常。
public class Read extends AsyncTask <String,Integer,String>
{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try{
json = Verify();
return json.getString(params[0]);
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}
catch (JSONException e)
{
}
return null;
}
我目前正在通过 localhost 连接。
问题发生在以下行: HttpResponse r = client.execute(get);
它没有执行,VM 上的应用程序正在崩溃。
我已将代码修改为如下所示,但仍然出现相同的错误:
public JSONObject Verify(HttpResponse r) throws ClientProtocolException, IOException, JSONException
{
//StringBuilder url = new StringBuilder(URL);
//Adds the pin and IMEI.
//url.append(b);
//HttpGet get = new HttpGet (url.toString());
//HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if(status == 200)
{
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray timeline = new JSONArray(data);
JSONObject last = timeline.getJSONObject(0);
return last;
}
else
{
Toast.makeText(Authenticate.this, "error", Toast.LENGTH_LONG);
return null;
}
}
public class Read extends AsyncTask <String,Integer,String>
{
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
try{
HttpResponse r = client.execute(get);
json = Verify(r);
return json.getString(params[0]);
}
catch (ClientProtocolException e)
{
}
catch (IOException e)
{
}
catch (JSONException e)
{
}
return null;
}
Log Cat 给了我这个错误:07-10 20:53:23.578: E/ActivityThread(661): Service com.android.exchange.ExchangeService has leaked ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d17eb0 那原定于此处 07-10 20:53:23.578: E/ActivityThread(661): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService 已泄露 ServiceConnection com.android.emailcommon.service.ServiceProxy$ProxyConnection@40d17eb0最初绑定在这里 07-10 20:53:23.578: E/ActivityThread(661): at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:969) 07-10 20:53:23.578: E/ActivityThread( 661): 在 android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 07-10 20:53:23.578: E/ActivityThread(661): 在 android.app.ContextImpl.bindService(ContextImpl.java:1418) 07 -10 20:53:23.578:E/ActivityThread(661): 在 android.app.ContextImpl.bindService(ContextImpl.java:1407) 07-10 20:53:23.578: E/ActivityThread(661): 在 android.content.ContextWrapper.bindService(ContextWrapper.java :473) 07-10 20:53:23.578: E/ActivityThread(661): 在 com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157) 07-10 20:53:23.578: E/ActivityThread (661): 在 com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 07-10 20:53:23.578: E/ActivityThread(661): 在 com.android.emailcommon.service.ServiceProxy。测试(ServiceProxy.java:191)07-10 20:53:23.578:E/ActivityThread(661):在 com.android.exchange.ExchangeService$7.run(ExchangeService.java:1850)07-10 20:53:23.578 : E/ActivityThread(661): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 07-10 20:53:23.578: E/ActivityThread(661): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 07-10 20:53:23.578: E/ActivityThread(661): at android.os.AsyncTask$2.call(AsyncTask.java:287) 07 -10 20:53:23.578: E/ActivityThread(661): 在 java.util.concurrent.FutureTask.run(FutureTask.java:234) 07-10 20:53:23.578: E/ActivityThread(661): 在 java .util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 07-10 20:53:23.578: E/ActivityThread(661): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) 07-10 20:53:23.578: E/ActivityThread(661): 在 java.lang.Thread.run(Thread.java:856) 07-10 20:53:23.588: E/StrictMode(661): null 07- 10 20:53:23.588: E/StrictMode(661): android.app.ServiceConnectionLeaked: Service com.android.exchange.ExchangeService 已泄露 ServiceConnection com.android.emailcommon.service。ServiceProxy$ProxyConnection@40d17eb0 最初绑定在这里 07-10 20:53:23.588: E/StrictMode(661): at android.app.LoadedApk$ServiceDispatcher.(LoadedApk.java:969) 07-10 20:53:23.588 : E/StrictMode(661): 在 android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863) 07-10 20:53:23.588: E/StrictMode(661): 在 android.app.ContextImpl.bindService(ContextImpl. java:1418) 07-10 20:53:23.588: E/StrictMode(661): 在 android.app.ContextImpl.bindService(ContextImpl.java:1407) 07-10 20:53:23.588: E/StrictMode(661) : 在 android.content.ContextWrapper.bindService(ContextWrapper.java:473) 07-10 20:53:23.588: E/StrictMode(661): 在 com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:157 ) 07-10 20:53:23.588: E/StrictMode(661): 在 com.android.emailcommon.service.ServiceProxy.setTask(ServiceProxy.java:145) 07-10 20:53:23.588:E/StrictMode(661): 在 com.android.emailcommon.service.ServiceProxy.test(ServiceProxy.java:191) 07-10 20:53:23.588: E/StrictMode(661): 在 com.android.exchange.ExchangeService $7.run(ExchangeService.java:1850) 07-10 20:53:23.588: E/StrictMode(661): at com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:551) 07-10 20 :53:23.588: E/StrictMode(661): 在 com.android.emailcommon.utility.Utility$2.doInBackground(Utility.java:549) 07-10 20:53:23.588: E/StrictMode(661): 在 android .os.AsyncTask$2.call(AsyncTask.java:287) 07-10 20:53:23.588: E/StrictMode(661): at java.util.concurrent.FutureTask.run(FutureTask.java:234) 07-10 20:53:23.588: E/StrictMode(661): 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 07-10 20:53:23.588: E/StrictMode(661): 在 java.util .concurrent.ThreadPoolExecutor$Worker。运行(ThreadPoolExecutor.java:573)07-10 20:53:23.588:E/StrictMode(661):在 java.lang.Thread.run(Thread.java:856)07-10 20:53:23.588:W/ ActivityManager(291): Unbind failed: 找不到 android.os.BinderProxy@4100de60 的连接