我收到这个错误。我不知道出了什么问题。有人可以帮我吗?搜索了一下,但不知道如何解决它......有点急。
这是我的代码:
package nearest.moskee.almawada;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Locale;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.google.android.maps.GeoPoint;
public class MoskeeJSON extends Activity {
private Handler mHandler = new Handler(Looper.getMainLooper());
String url;
HttpClient httpclient;
InputStream is = null;
private class MyAsyncTask extends AsyncTask<Void, Void, Void> {
ProgressDialog mProgressDialog;
@Override
protected void onPostExecute(Void result) {
mProgressDialog.dismiss();
}
@Override
protected void onPreExecute() {
mProgressDialog = ProgressDialog.show(MoskeeJSON.this,
"Loading...", "Data is Loading...");
}
@Override
protected Void doInBackground(Void... params) {
try {
HttpPost httppost = new HttpPost(url);
//HttpGet httppost = new HttpGet(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("url", url);
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
return null;
}
}
public JSONArray getCloseMosquesInJSON(float lat, float lng, float radius) {
String result = "";
try {
httpclient = new DefaultHttpClient();
url = "http://www.moskee.org/finder/getCloseDataInJSON.php?lat="
+ lat + "&lng=" + lng + "&radius=" + radius;
new MyAsyncTask().execute();
Log.v("URL =>", url);
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// convert response to string
try {
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();
Log.e("result", result);
Log.e("resultLength", result.length() + "");
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// parse json data
if (result.length() == 5) {
Log.i("result is ", "LEEG");
return null;
} else {
JSONArray jArray = null;
try {
jArray = new JSONArray(result);
} catch (JSONException e) {
Log.e("log_tag", "Error parrsing data " + e.toString());
}
return jArray;
}
}
JSONObject jsonObject;
StringBuilder stringBuilder;
}
错误
06-07 15:04:07.329: I/dalvikvm(1643): threadid=3: 对信号 3 做出反应 06-07 15:04:07.370: I/dalvikvm(1643): 将堆栈跟踪写入 '/data/anr/ traces.txt' 06-07 15:04:07.828: I/dalvikvm(1643): threadid=3: 对信号 3 做出反应 06-07 15:04:07.898: I/dalvikvm(1643): 将堆栈跟踪写入 '/ data/anr/traces.txt' 06-07 15:04:07.988: D/gralloc_goldfish(1643): 没有检测到 GPU 仿真的仿真器。06-07 15:04:24.098: D/InputEventConsistencyVerifier(1643): KeyEvent: ACTION_UP 但键没有按下。06-07 15:04:24.098: D/InputEventConsistencyVerifier(1643): 在 android.widget.EditText@412aa7f0 06-07 15:04:24.098: D/InputEventConsistencyVerifier(1643): 0: 在 16907476000000 发送,KeyEvent { action= ACTION_UP,keyCode=KEYCODE_TAB,scanCode=15,metaState=0,flags=0x8,repeatCount=0,eventTime=16907476,
莫斯科结果
package nearest.moskee.almawada;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class MoskeeResults extends MapActivity {
MapView mapView;
MapController mc;
GeoPoint p;
@SuppressWarnings("unused")
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.myMap);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.iconmoskee);
OverlayItems itemizedoverlay = new OverlayItems(drawable,this);
try {
MoskeeJSON m = new MoskeeJSON();
Bundle extras = getIntent().getExtras();
float lat = 0;
float lng = 0;
float radius = 1;
lat = (float) extras.getDouble("lat");
lng = (float) extras.getDouble("lng");
JSONArray arrMosques = m.getCloseMosquesInJSON(lat, lng, radius);
if (arrMosques != null) {
Log.i("Array aangemaakt", "Array is aangemaakt, het bevat "
+ arrMosques.length() + " moskeëen");
for (int i = 0; i < arrMosques.length(); i++) {
JSONObject row;
row = arrMosques.getJSONObject(i);
double jlat = row.getDouble("Latitude");
double jlng = row.getDouble("Longitude");
OverlayItem overlayitem = new OverlayItem(new GeoPoint(
(int) (jlat * 1e6), (int) (jlng * 1e6)),
row.getString("Naam"), row.getString("Straat"));
itemizedoverlay.addOverlay(overlayitem);
Log.i("=>", "Another mosque is added to the map");
}
Log.i("Array aangemaakt", "Array is aangemaakt, het bevat "
+ arrMosques.length() + " moskeëen");
AlertDialog alert = new AlertDialog.Builder(this)
.setTitle("Aantal gevonden moskeëen")
.setMessage(
"Er zijn " + arrMosques.length()
+ " moskeëen gevonden in deze straal")
.create();
alert.show();
} else {
AlertDialog alert = new AlertDialog.Builder(this)
.setTitle("Aantal gevonden moskeëen")
.setMessage(
"Er zijn geen moskeëen gevonden in deze straal.\nProbeer opnieuw te zoeken met een groter bereik")
.create();
alert.show();
}
mapOverlays.add(itemizedoverlay);
mc = mapView.getController();
GeoPoint center = new GeoPoint((int) (lat * 1e6), (int) (lng * 1e6));
Log.i("Center map?", "" + (int) (lat * 1e6) + ","
+ (int) (lng * 1e6));
mc.setCenter(center);
Log.i("Center map?", "Toegepast zonder erreurs");
mc.setZoom(17);
} catch ( JSONException e) {
// TODO Auto-generated catch block
Log.i("JASOEN EXCEPTIOEN",
"I have absolutely no idea what's going on..."
+ e.getMessage());
e.printStackTrace();
}
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}