我不想在谷歌地图中添加标记,我从数据库获取纬度和经度..
此代码用于从数据库获取数据并添加标记
public String getJSONUrl(String url) {
StringBuilder str = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) { // Download OK
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
str.append(line);
}
} else {
Log.e("Log", "Failed to download result..");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str.toString();
}
private void WC(final String alamat) {
class SendPostReqAsyncTask extends AsyncTask<String, Integer, String> {
@Override
protected void onPreExecute() {
myProgressDialog = new ProgressDialog(PetaActivity.this);
myProgressDialog.setIndeterminate(true);
myProgressDialog.setMessage("Loading...");
myProgressDialog.setCancelable(true);
myProgressDialog.show();
}
@Override
protected String doInBackground(String... params) {
String text = null;
String urlwc = alamat;
try {
JSONArray data = new JSONArray(getJSONUrl(urlwc));
if (data.length() != 0) {
HashMap<String, String> map;
for (int i = 0; i < data.length(); i++) {
JSONObject c = data.getJSONObject(i);
map = new HashMap<String, String>();
map.put("id_jalan", c.getString("id_jalan"));
map.put("nama_jalan", c.getString("nama_jalan"));
map.put("latitude", c.getString("latitude"));
map.put("longitude", c.getString("longitude"));
map.put("foto", c.getString("foto"));
MyArrListMarker.add(map);
//end add marker
publishProgress((int) (i));
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
text = e.getMessage();
}
//
return text;
}
@Override
protected void onProgressUpdate(Integer... progress) {
maps.addMarker(new MarkerOptions()
.title("WC Umum")
.snippet("24 Jam")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.toilet))
.position(new LatLng(
Double.parseDouble(MyArrListMarker.get(progress[0]).get("latitude")),
Double.parseDouble(MyArrListMarker.get(progress[0]).get("longitude"))))
);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
myProgressDialog.dismiss();
if (result != null) {
AlertDialog alertDialog = new AlertDialog.Builder(PetaActivity.this).create();
alertDialog.setTitle("Koneksi Gagal");
alertDialog.setMessage("Silahkan coba lagi");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "TUTUP", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
}
}
SendPostReqAsyncTask sendPostReqAsyncTask = new SendPostReqAsyncTask();
sendPostReqAsyncTask.execute(alamat);
}
但添加标记时出现错误,但如果标记我删除它没有错误
这是logcat
12:36:26.356 31593-31593/lapor.jalan.rusak.com.laporjalanrusak E/dalvikvm: Could not find class 'com.google.android.chimera.Activity', referenced from method lq.b
12-29 12:36:27.276 31593-31593/lapor.jalan.rusak.com.laporjalanrusak E/AndroidRuntime: FATAL EXCEPTION: main
Process: lapor.jalan.rusak.com.laporjalanrusak, PID: 31593
java.lang.NullPointerException
at lapor.jalan.rusak.com.laporjalanrusak.PetaActivity$1SendPostReqAsyncTask.onProgressUpdate(PetaActivity.java:378)
at lapor.jalan.rusak.com.laporjalanrusak.PetaActivity$1SendPostReqAsyncTask.onProgressUpdate(PetaActivity.java:334)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:648)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5692)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
12-29 12:36:28.776 31593-31864/lapor.jalan.rusak.com.laporjalanrusak E/DynamiteModule: Failed to load DynamiteLoader: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.dynamite.DynamiteModule$DynamiteLoaderClassLoader" on path: DexPathList[[zip file "/data/app/lapor.jalan.rusak.com.laporjalanrusak-9.apk", zip file "/data/data/lapor.jalan.rusak.com.laporjalanrusak/code_cache/secondary-dexes/lapor.jalan.rusak.com.laporjalanrusak-9.apk.classes2.zip"],nativeLibraryDirectories=[/data/app-lib/lapor.jalan.rusak.com.laporjalanrusak-9, /vendor/lib, /system/lib]]
答案 0 :(得分:0)
您logcat
的最后一行
E / DynamiteModule:无法加载DynamiteLoader:java.lang.ClassNotFoundException:未找到类&#34; com.google.android.gms.dynamite.DynamiteModule $ DynamiteLoaderClassLoader&#34;在路径上:DexPathList [[zip文件&#34; /data/app/lapor.jalan.rusak.com.laporjalanrusak-9.apk" ;, zip文件&#34; /data/data/lapor.jalan.rusak .com.laporjalanrusak / code_cache /次级dexes / lapor.jalan.rusak.com.laporjalanrusak-9.apk.classes2.zip&#34],nativeLibraryDirectories = [/数据/ APP-LIB / lapor.jalan.rusak.com .laporjalanrusak-9,/ vendor / lib,/ system / lib]]
说ClassNotFoundException
表示你没有上课。这是因为您可能没有添加lib dependency
或者它在运行时被删除。