请帮助我,我在这里遇到一些问题。这是我的BandaraMap.java:
public class BandaraMap extends FragmentActivity implements OnInfoWindowClickListener, ActionBar.OnNavigationListener
{
private GoogleMap map;
private JSONHelper json;
private ProgressDialog pDialog;
private LatLng myLocation;
private List<Map_POI> listPOI_Bandara;
private final String URL_API = "http://laraswedding.com/56410097/data_bandara.php";
private final String URL_API_Selected1 = "http://laraswedding.com/56410097/data_bandara.php?key=Bandara_Halim_Perdana_Kusuma";
private final String URL_API_Selected2 = "http://laraswedding.com/56410097/data_bandara.php?key=Bandara_Soekarno-Hatta";
public static final String KEY_NAMA = "nama";
public static final String KEY_ALAMAT = "alamat";
public static final String KEY_LAT_TUJUAN = "lat_tujuan";
public static final String KEY_LNG_TUJUAN = "lng_tujuan";
public static final String KEY_LAT_ASAL = "lat_asal";
public static final String KEY_LNG_ASAL = "lng_asal";
//private LatLng user_location;
// Members for layout
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private ListView mDrawerList;
private CharSequence mTitle;
private CharSequence mDrawerTitle;
private String[] mTitles;
ActionBar actionBar;
@Override
protected void onCreate(Bundle savedInstanceState)
{
/*requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);*/
super.onCreate(savedInstanceState);
setContentView(R.layout.test_map);
InitSpinnerLayout();
InitNavigationDrawableLayout();
json = new JSONHelper();
/*myLocation = new LatLng(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(myLocation.latitude, myLocation.longitude), 13));*/
new AsynTaskMain().execute();
setupMapIfNeeded();
//bounds = boundsBuilder.build();
//map.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
}
private void InitSpinnerLayout() {
actionBar = getActionBar();
ArrayAdapter<CharSequence> mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list1,
android.R.layout.simple_spinner_dropdown_item);
//mSpinnerList = (ListView) findViewById(android.R.id.list);
//mSpinnerList.setAdapter(mSpinnerAdapter);
//mSpinnerList.setOnItemClickListener(new SpinnerItemClickListener());
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
/*SpinnerAdapter spinneradapter = new SpinnerAdapter(this,
R.layout.spinner_drawer_item, mSpinners);*/
actionBar.setListNavigationCallbacks(mSpinnerAdapter , (OnNavigationListener) this);
//mSpinners = getResources().getStringArray(R.array.action_list);
}
/**
* Initializes the activities layout.
*/
private void InitNavigationDrawableLayout() {
actionBar = getActionBar();
mTitles = getResources().getStringArray(R.array.drawer_items_array_bandara);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(this,
R.layout.drawer_item, mTitles);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mTitle = mDrawerTitle = getTitle();
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, R.string.drawer_open,
R.string.drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
actionBar.setTitle(mTitle);
}
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
actionBar.setTitle(mDrawerTitle);
//getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
}
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
`@Override`<br/>
`public void onItemClick(AdapterView<?> parent, View view, int position,`<br/>
`long id) {`<br/>
`switch (position) `<br/>
`{`<br/>
`case 0:`<br/>
`new AsynTaskMain().execute();`<br/>
`setupMapIfNeeded();`<br/>
break;
case 1:
new AsynTaskMain().isCancelled();
new AsynTaskMain1().execute();
setupMapIfNeeded();
/*for (int i = 0; i < listPOI_Bandara.size(); i++)
{
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()), 12));
}
/*for (int i = 0; i < listPOI_Bandara.size(); i++)
{
map.addMarker(new MarkerOptions()
.position(new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()))
.title(listPOI_Bandara.get(i).getNama())
.snippet(listPOI_Bandara.get(i).getAlamat())
.icon(BitmapDescriptorFactory`
.fromResource(R.drawable.marker_bandara_map)));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()), 12));
Toast.makeText(getApplicationContext(), "Bandara Halim Perdana Kusuma", Toast.LENGTH_LONG).show();
}*/
break;
case 2:
new AsynTaskMain().isCancelled();
new AsynTaskMain2().execute();
setupMapIfNeeded();
break;
default:
break;
}
mDrawerList.setItemChecked(position, true);
setTitle(mTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
`}`<br/><br/>
`}`<br/><br/>
private void setupMapIfNeeded()
{
if (map == null)
{
FragmentManager fragmentManager = getSupportFragmentManager();
SupportMapFragment supportMapFragment = (SupportMapFragment) fragmentManager.findFragmentById(R.id.maps);
map = supportMapFragment.getMap();
map.setTrafficEnabled(true);
if (map != null)
{
setupMap();
}
}
}
private void setupMap()
{
map.setMyLocationEnabled(true);
map.setOnInfoWindowClickListener(this);
moveToMyLocation();
}
private void moveToMyLocation()
{
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false));
//user_location = new LatLng(location.getLatitude(), location.getLongitude());
if (location != null)
{
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(location.getLatitude(), location.getLongitude()), 13));
Toast.makeText(getApplicationContext(), (R.string.Toast), Toast.LENGTH_LONG).show();
/*marker_user = map.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude()))
.title("Posisi Anda Saat Ini")
//.snippet(" Tangerang-Banten ")
//.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker_bandara_map)));
marker_user.showInfoWindow();*/
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
return super.onPrepareOptionsMenu(menu);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
switch (item.getItemId()) {
case R.id.action_about:
startActivity(new Intent(this, AboutActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public boolean onNavigationItemSelected(int position, long itemId) {
switch (position) {
case 0:
break;
case 1:
Intent intent = new Intent(getApplicationContext(),BandaraAR.class);
startActivity(intent);
//mArchitectView.load("video.html");
break;
default:
break;
}
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), "text", Toast.LENGTH_LONG).show();
return true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
protected void onResume()
{
// TODO Auto-generated method stub
super.onResume();
int resCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resCode != ConnectionResult.SUCCESS)
{
GooglePlayServicesUtil.getErrorDialog(resCode, this, 1);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
//Handle the back ImageButton
if(keyCode == KeyEvent.KEYCODE_BACK) {
checkBack();
return true;
}
else {
return super.onKeyDown(keyCode, event);
}
}
private void checkBack()
{
Intent kembali = new Intent(getApplicationContext(),MasukAplikasi.class);
startActivity(kembali);
}
private class AsynTaskMain extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
pDialog.dismiss();
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
for (int i = 0; i < listPOI_Bandara.size(); i++)
{
if (i != listPOI_Bandara.size() - 1)
map.addMarker(new MarkerOptions()
.position(new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()))
.title(listPOI_Bandara.get(i).getNama())
.snippet(listPOI_Bandara.get(i).getAlamat())
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker_bandara_map)));
else if (i == listPOI_Bandara.size() - 1)
{
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(-6.175392,106.827153), 10));
/*map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()), 10));*/
//boundsBuilder.include(new LatLng(listPOI_Bandara.get(i).getLat(), listPOI_Bandara.get(i).getLng()));
//marker_bandara.showInfoWindow();
}
}
}
});
super.onPostExecute(result);
}
@Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(BandaraMap.this);
pDialog.setMessage("Loading....");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params)
{
// TODO Auto-generated method stub
JSONObject jObject = json.getJSONFromURL(URL_API);
listPOI_Bandara = json.getPOI_BandaraAll(jObject);
return null;
}
}
private class AsynTaskMain1 extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
pDialog.dismiss();
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
for (int i = 0; i < listPOI_Bandara.size(); i++)
{
/*if (i != listPOI_Bandara.size() - 1)
{*/
map.addMarker(new MarkerOptions()
.position(new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()))
.title(listPOI_Bandara.get(i).getNama())
.snippet(listPOI_Bandara.get(i).getAlamat())
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker_bandara_map)));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()), 12));
//}
/*else if (i == listPOI_Bandara.size() -1)
{
}*/
//boundsBuilder.include(new LatLng(listPOI_Bandara.get(i).getLat(), listPOI_Bandara.get(i).getLng()));
//marker_bandara.showInfoWindow();
}
}
});
super.onPostExecute(result);
Toast.makeText(getApplicationContext(), "Bandara Halim Perdana Kusuma", Toast.LENGTH_LONG).show();
}
@Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(BandaraMap.this);
pDialog.setMessage("Loading....");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params)
{
// TODO Auto-generated method stub
JSONObject jObject1 = json.getJSONFromURL(URL_API_Selected1);
listPOI_Bandara = json.getPOI_BandaraAll(jObject1);
return null;
}
}
private class AsynTaskMain2 extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPostExecute(Void result)
{
// TODO Auto-generated method stub
pDialog.dismiss();
runOnUiThread(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
for (int i = 0; i < listPOI_Bandara.size(); i++)
{
map.addMarker(new MarkerOptions()
.position(new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()))
.title(listPOI_Bandara.get(i).getNama())
.snippet(listPOI_Bandara.get(i).getAlamat())
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.marker_bandara_map)));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(listPOI_Bandara.get(i).getLat(),
listPOI_Bandara.get(i).getLng()), 12));
//boundsBuilder.include(new LatLng(listPOI_Bandara.get(i).getLat(), listPOI_Bandara.get(i).getLng()));
//marker_bandara.showInfoWindow();
}
}
});
super.onPostExecute(result);
Toast.makeText(getApplicationContext(), "Bandara Soekarno-Hatta", Toast.LENGTH_LONG).show();
}
@Override
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(BandaraMap.this);
pDialog.setMessage("Loading....");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(Void... params)
{
// TODO Auto-generated method stub
JSONObject jObject2 = json.getJSONFromURL(URL_API_Selected2);
listPOI_Bandara = json.getPOI_BandaraAll(jObject2);
return null;
}
}
@Override
public void onInfoWindowClick(Marker marker_tujuan)
{
// marker id -> m0, m1, m2 dst..
String id = marker_tujuan.getId();
id = id.substring(1);
myLocation = new LatLng(map.getMyLocation().getLatitude(), map.getMyLocation().getLongitude());
if (myLocation != null)
{
Bundle bundle = new Bundle();
bundle.putString(KEY_NAMA, listPOI_Bandara.get(Integer.parseInt(id)).getNama());
bundle.putString(KEY_ALAMAT, listPOI_Bandara.get(Integer.parseInt(id)).getAlamat());
bundle.putDouble(KEY_LAT_TUJUAN, marker_tujuan.getPosition().latitude);
bundle.putDouble(KEY_LNG_TUJUAN, marker_tujuan.getPosition().longitude);
bundle.putDouble(KEY_LAT_ASAL, myLocation.latitude);
bundle.putDouble(KEY_LNG_ASAL, myLocation.longitude);
Intent i = new Intent(BandaraMap.this, InfoTempatActivity.class);
i.putExtras(bundle);
startActivity(i);
} else
{
Toast.makeText(this, "Tidak dapat menemukan lokasi anda ", Toast.LENGTH_LONG).show();
}
}
}
而且,这是我的JSONHelper.java:
public class JSONHelper
{
private InputStream is = null;
private JSONObject jsonObject = null;
private String json = "";
private final String TAG_BANDARA = "data_bandara";
private final String TAG_PELABUHAN = "data_pelabuhan";
private final String TAG_STASIUN = "data_stasiun";
private final String TAG_TERMINAL = "data_terminal";
private final String TAG_ID = "id";
private final String TAG_NAMA = "nama";
private final String TAG_ALAMAT = "alamat";
private final String TAG_LAT = "lat";
private final String TAG_LNG = "lng";
private final String TAG_ROUTES = "routes";
private final String TAG_LEGS = "legs";
private final String TAG_STEPS = "steps";
private final String TAG_POLYLINE = "polyline";
private final String TAG_POINTS = "points";
private final String TAG_START = "start_location";
private final String TAG_END = "end_location";
public JSONObject getJSONFromURL(String url)
{
try
{
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
} catch (ClientProtocolException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
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();
json = sb.toString();
} catch (Exception e)
{
// TODO: handle exception
}
try
{
jsonObject = new JSONObject(json);
} catch (JSONException e)
{
// TODO: handle exception
}
return jsonObject;
}
public ArrayList<Map_POI> getPOI_BandaraAll(JSONObject jobj)
{
ArrayList<Map_POI> listPOI_Bandara = new ArrayList<Map_POI>();
try
{
JSONArray arrayPOI_Bandara = jobj.getJSONArray(TAG_BANDARA);
for (int i = 0; i < arrayPOI_Bandara.length(); i++)
{
JSONObject jobject = arrayPOI_Bandara.getJSONObject(i);
Log.d("log", "muter ke " + i);
listPOI_Bandara.add(new Map_POI( jobject.getInt(TAG_ID), jobject.getString(TAG_NAMA), jobject
.getString(TAG_ALAMAT), jobject
.getDouble(TAG_LAT), jobject.getDouble(TAG_LNG)));
}
} catch (JSONException e)
{
e.printStackTrace();
}
return listPOI_Bandara;
}
public ArrayList<Map_POI> getPOI_PelabuhanAll(JSONObject jobj)
{
ArrayList<Map_POI> listPOI_Pelabuhan = new ArrayList<Map_POI>();
try
{
JSONArray arrayPOI_Pelabuhan = jobj.getJSONArray(TAG_PELABUHAN);
for (int i = 0; i < arrayPOI_Pelabuhan.length(); i++)
{
JSONObject jobject = arrayPOI_Pelabuhan.getJSONObject(i);
Log.d("log", "muter ke " + i);
listPOI_Pelabuhan.add(new Map_POI( jobject.getInt(TAG_ID), jobject.getString(TAG_NAMA), jobject
.getString(TAG_ALAMAT), jobject
.getDouble(TAG_LAT), jobject.getDouble(TAG_LNG)));
}
} catch (JSONException e)
{
e.printStackTrace();
}
return listPOI_Pelabuhan;
}
public ArrayList<Map_POI> getPOI_StasiunAll(JSONObject jobj)
{
ArrayList<Map_POI> listPOI_Stasiun = new ArrayList<Map_POI>();
try
{
JSONArray arrayPOI_Stasiun = jobj.getJSONArray(TAG_STASIUN);
for (int i = 0; i < arrayPOI_Stasiun.length(); i++)
{
JSONObject jobject = arrayPOI_Stasiun.getJSONObject(i);
Log.d("log", "muter ke " + i);
listPOI_Stasiun.add(new Map_POI( jobject.getInt(TAG_ID), jobject.getString(TAG_NAMA), jobject
.getString(TAG_ALAMAT), jobject
.getDouble(TAG_LAT), jobject.getDouble(TAG_LNG)));
}
} catch (JSONException e)
{
e.printStackTrace();
}
return listPOI_Stasiun;
}
public ArrayList<Map_POI> getPOI_TerminalAll(JSONObject jobj)
{
ArrayList<Map_POI> listPOI_Terminal = new ArrayList<Map_POI>();
try
{
JSONArray arrayPOI_Terminal = jobj.getJSONArray(TAG_TERMINAL);
for (int i = 0; i < arrayPOI_Terminal.length(); i++)
{
JSONObject jobject = arrayPOI_Terminal.getJSONObject(i);
Log.d("log", "muter ke " + i);
listPOI_Terminal.add(new Map_POI( jobject.getInt(TAG_ID), jobject.getString(TAG_NAMA), jobject
.getString(TAG_ALAMAT), jobject
.getDouble(TAG_LAT), jobject.getDouble(TAG_LNG)));
}
} catch (JSONException e)
{
e.printStackTrace();
}
return listPOI_Terminal;
}
/*
* Untuk decode Polyline
*
* @params String
*
* @return List<LatLng>
*/
private List<LatLng> decodePoly(String encoded)
{
List<LatLng> poly = new ArrayList<LatLng>();
int index = 0, len = encoded.length();
int lat = 0, lng = 0;
while (index < len)
{
int b, shift = 0, result = 0;
do
{
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lat += dlat;
shift = 0;
result = 0;
do
{
b = encoded.charAt(index++) - 63;
result |= (b & 0x1f) << shift;
shift += 5;
} while (b >= 0x20);
int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
lng += dlng;
LatLng position = new LatLng((double) lat / 1E5, (double) lng / 1E5);
poly.add(position);
}
return poly;
}
/*
* Untuk mendapatkan direction
*
* @params JSONObject
*
* @return List<LatLng>
*/
public List<LatLng> getDirection(JSONObject jObj)
{
List<LatLng> directions = new ArrayList<LatLng>();
try
{
JSONObject objRoute = jObj.getJSONArray(TAG_ROUTES).getJSONObject(0);
JSONObject objLegs = objRoute.getJSONArray(TAG_LEGS).getJSONObject(0);
JSONArray arraySteps = objLegs.getJSONArray(TAG_STEPS);
for (int wi2t = 0; wi2t < arraySteps.length(); wi2t++)
{
JSONObject step = arraySteps.getJSONObject(wi2t);
JSONObject objStart = step.getJSONObject(TAG_START);
JSONObject objEnd = step.getJSONObject(TAG_END);
double latStart = objStart.getDouble(TAG_LAT);
double lngStart = objStart.getDouble(TAG_LNG);
directions.add(new LatLng(latStart, lngStart));
JSONObject poly = step.getJSONObject(TAG_POLYLINE);
String encodedPoly = poly.getString(TAG_POINTS);
List<LatLng> decodedPoly = decodePoly(encodedPoly);
for (int eka = 0; eka < decodedPoly.size(); eka++)
{
directions.add(new LatLng(decodedPoly.get(eka).latitude, decodedPoly.get(eka).longitude));
}
double latEnd = objEnd.getDouble(TAG_LAT);
double lngEnd = objEnd.getDouble(TAG_LNG);
directions.add(new LatLng(latEnd, lngEnd));
}
} catch (JSONException e)
{
// TODO: handle exception
}
return directions;
}
}
这是我在logcat上的问题:
`09-17 02:43:37.969: W/dalvikvm(14200): threadid=1: thread exiting with uncaught exception (group=0x41dc4930)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): FATAL EXCEPTION: main`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at java.util.ArrayList.get(ArrayList.java:304)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at com.slowbrocorp.aplikasiargpsdangistempattransportasiumum.BandaraMap.onInfoWindowClick(BandaraMap.java:571)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at com.google.android.gms.maps.GoogleMap$12.e(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at com.google.android.gms.maps.internal.g$a.onTransact(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at android.os.Binder.transact(Binder.java:310)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at gsh.a(SourceFile:82)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at oup.b(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at oqn.g(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at oqn.a(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at okj.b(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at ole.onSingleTapConfirmed(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at nyi.onSingleTapConfirmed(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at nyk.handleMessage(Unknown Source)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at android.os.Handler.dispatchMessage(Handler.java:99)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at android.os.Looper.loop(Looper.java:137)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at android.app.ActivityThread.main(ActivityThread.java:5061)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at java.lang.reflect.Method.invokeNative(Native Method)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at java.lang.reflect.Method.invoke(Method.java:511)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)`<br/>
`09-17 02:43:38.008: E/AndroidRuntime(14200): at dalvik.system.NativeStart.main(Native Method)`<br/>
当我在draweritemclicklistener上选择案例2并执行AsynTaskMain2()时,它停止工作。请帮我解决这个问题:(
答案 0 :(得分:1)
您的堆栈跟踪说明如下:
09-17 02:43:38.008: E/AndroidRuntime(14200): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
09-17 02:43:38.008: E/AndroidRuntime(14200): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
09-17 02:43:38.008: E/AndroidRuntime(14200): at java.util.ArrayList.get(ArrayList.java:304)
09-17 02:43:38.008: E/AndroidRuntime(14200): at com.slowbrocorp.aplikasiargpsdangistempattransportasiumum.BandaraMap.onInfoWindowClick(BandaraMap.java:571)
这意味着:对ArrayList.get()的调用是从MandaraMap.onInfoWindowClick()第571行开始的,参数为1,这是不合法的,因为ArrayList中只有一个元素。
第571行是哪一行?我在您发布的代码中看不到get()
中onInfoWindowClick()
的任何调用,这让我觉得您发布的代码不是您正在运行的代码。