我见过其他人有这个问题,但我不清楚如何解决这个问题。实际上我的代码在将Android更新到第22版之前已经工作了21个。希望那里有人有类似的经历。无论如何这是我的代码。
@Override
protected JSONArray doInBackground(String...params) {
HttpClient client = new DefaultHttpClient();
String url = params[0] + "?longitude=" + curr_longitude + "&latitude=" + curr_lat;
HttpGet httpGet = new HttpGet(url);
StringBuilder builder = new StringBuilder();
org.apache.http.HttpResponse response = null;
try {
response = client.execute(httpGet);
} catch (ClientProtocolException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null)
{
builder.append(line);
}//end while
JSONArray jsonarray = new JSONArray(builder.toString());
return jsonarray;
}//end if
else {
}}catch (Exception e){
Log.e("log_tag", "Error in http connection" +e.getMessage());
}//end try catch
return null;
}//end function
这是logcat
06-27 20:22:43.808: W/dalvikvm(29761): threadid=23: thread exiting with uncaught exception (group=0x40da1930)
06-27 20:22:43.808: E/AndroidRuntime(29761): FATAL EXCEPTION: AsyncTask #1
06-27 20:22:43.808: E/AndroidRuntime(29761): java.lang.RuntimeException: An error occured while executing doInBackground()
06-27 20:22:43.808: E/AndroidRuntime(29761): at android.os.AsyncTask$3.done(AsyncTask.java:299)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
06-27 20:22:43.808: E/AndroidRuntime(29761): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.lang.Thread.run(Thread.java:856)
06-27 20:22:43.808: E/AndroidRuntime(29761): Caused by: java.lang.IllegalStateException: Scheme 'htpp' not registered.
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.conn.ProxySelectorRoutePlanner.determineRoute(ProxySelectorRoutePlanner.java:157)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:596)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-27 20:22:43.808: E/AndroidRuntime(29761): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
06-27 20:22:43.808: E/AndroidRuntime(29761): at com.example.mapmapagain.MainActivity$GetfromServer.doInBackground(MainActivity.java:456)
06-27 20:22:43.808: E/AndroidRuntime(29761): at com.example.mapmapagain.MainActivity$GetfromServer.doInBackground(MainActivity.java:1)
06-27 20:22:43.808: E/AndroidRuntime(29761): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-27 20:22:43.808: E/AndroidRuntime(29761): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-27 20:22:43.808: E/AndroidRuntime(29761): ... 4 more
非常感谢你的帮助!!!
答案 0 :(得分:1)
错误消息是:
Caused by: java.lang.IllegalStateException: Scheme 'htpp' not registered.
htpp
似乎应该是http
。检查您的网址。