我創建了一個列表如下:如何檢查該列表是否爲空?
Geocoder gc = new Geocoder(this);
List<Address> list = gc.getFromLocationName(location, 1);
Address add = list.get(0);
if (add== null)
{
Toast.makeText(this,"address not found", Toast.LENGTH_SHORT).show();
return;
}
getFromLocationName
返回地址列表的功能。 如果找不到地址,則會引發(Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0)
。
我做了檢查,但它不工作,我的應用程序只是停止...
任何想法,爲什麼?
怎麼樣list.isEmpty()? – mosaad 2014-10-01 10:00:03
list.isEmpty();檢查它 – 2014-10-01 10:01:41
好吧,我檢查它... – 2014-10-01 10:02:46