-1
java class:
@Override
protected String doInBackground(String... params) {
InputStream is = null;
String result = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("",""));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(strURL);
try{
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine())!=null){
sb.append(line + "\n");
}
is.close();
result=sb.toString();
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
String pid=""+json_data.getString("pid");
String region = json_data.getString("region");
String name = json_data.getString("name");
Double longi = json_data.getDouble("longitude");
Double lati = json_data.getDouble("latitude");
//convert double variable to int variable
int d1 = (int) (lati * 1E6);
int d2 = (int) (longi * 1E6);
//convert int variable to String variable:
String latitude = ""+ d1;
String longitutde = ""+ d2;
Toast.makeText(HomePage.this, latitude, Toast.LENGTH_LONG).show();
}
} catch(Exception e)
{
Log.e("log_tag", "Error in http connection " + e.toString());
}
try{
jArray = new JSONArray(result);
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data " + e.toString());
}
return null;
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
}
}
}
日誌貓:錯誤.java.lang.NullPointerException
11-27 22:57:22.581: E/Trace(1675): error opening trace file: No such file or directory (2)
11-27 22:57:22.881: D/libEGL(1675): loaded /system/lib/egl/libEGL_emulation.so
11-27 22:57:22.885: D/(1675): HostConnection::get() New Host Connection established 0xb9087948, tid 1675
11-27 22:57:22.901: D/libEGL(1675): loaded /system/lib/egl/libGLESv1_CM_emulation.so
11-27 22:57:22.901: D/libEGL(1675): loaded /system/lib/egl/libGLESv2_emulation.so
11-27 22:57:23.185: W/EGL_emulation(1675): eglSurfaceAttrib not implemented
11-27 22:57:23.201: D/OpenGLRenderer(1675): Enabling debug mode 0
11-27 22:57:27.037: W/EGL_emulation(1675): eglSurfaceAttrib not implemented
11-27 22:57:29.181: W/EGL_emulation(1675): eglSurfaceAttrib not implemented
11-27 22:57:29.289: D/dalvikvm(1675): GC_CONCURRENT freed 120K, 3% free 6232K/6400K, paused 6ms+1ms, total 75ms
11-27 22:57:30.549: E/log_tag(1675): Error in http connection java.lang.NullPointerException
代替在日誌消息使用e.toString()的,使用格式Log.e(「log_tag」,「錯誤在http連接」 ,e);這將打印出堆棧跟蹤。 – panini
你已經在SO上發佈了2個問題,而且你實際上並沒有提供任何真實的描述 - 也許你應該先閱讀規則,然後返回 – Katana24
,無論如何,strUrl會持有什麼樣的價值?這可能只是一個無效的連接 – DigCamara