gc.getLocationFromName()始终是returnig null值。列表是空的我无法找到解决方案。
public void geoLocate(View view) throws IOException {
hideSoftKeyboard(view);
EditText etValue=(EditText)findViewById(R.id.etValue);
String location = etValue.getText().toString();
Log.d("-----Location :" , location);
Geocoder gc= new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> list=gc.getFromLocationName(location,1);
int size=list.size();
Log.d("Size---" ,""+size);
if(list!=null && list.size()>0) {
Address add = list.get(0);
String locality = add.getLocality();
Log.e("----Locality", locality);
Toast.makeText(this, locality, Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(this, "NULL VALUE RETURNED", Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:0)
@Dharma
替换
List<Address> list=gc.getFromLocationName(location,1);
与
List<Address> list= new ArrayList<>();
list = gc.getFromLocationName(location,1);