有人能讓我知道下面的代碼有什麼問題嗎? 我正試圖對存儲在「Options」變量中的數組進行排序。但它會拋出'空'異常。排序陣列不起作用
public static void CheckOptionsPresent(String s1) throws Exception
{
try
{
List optionsList=null;
webDriver.findElement(By.cssSelector("article.ContactInfo.active div.half-left.contactInfo div.idProvinceOfIssuance button")).click();
int listcount = webDriver.findElements(By.cssSelector("article.ContactInfo.active div.half-left.contactInfo div.idProvinceOfIssuance div ul li")).size();
System.out.println(listcount);
String[] options=new String[listcount];
for (int i=2; i<=listcount; i++)
{
options[i-1] = webDriver.findElement(By.cssSelector("article.ContactInfo.active div.half-left.contactInfo div.idProvinceOfIssuance div ul li:nth-child("+i+") a span")).getText();
System.out.println(options[i-1]);
}
System.out.println(options.length);
for(int j=0; j<options.length;j++)
{
for (int i=j+1 ; i<options.length; i++)
{
if(options[i].compareToIgnoreCase(options[j])<0)
{
String temp= options[j];
options[j]= options[i];
options[i]=temp;
}
}
System.out.println(options[j]);
}
}
catch (RuntimeException e)
{
System.out.println(e.getMessage());
throw new RuntimeException(e.getMessage());
}
}
輸出:
14
AB - Alberta
BC - British Columbia
MB - Manitoba
NB - New Brunswick
NL - Newfoundland and Labrador
NS - Nova Scotia
NT - Northwest Territories
NU - Nunavut
ON - Ontario
PE - Prince Edward Island
QC - Québec
SK - Saskatchewan
YT - Yukon Territory
14
下面是錯誤:
org.eclipse.debug.core.DebugException: com.sun.jdi.ClassNotLoadedException: Type has not been loaded occurred while retrieving component type of array.
for (int i=j+1 ; i<options.length; i++) {
if(options[i].compareToIgnoreCase(options[j])<0) {
String temp= options[j]; options[j]= options[i];
options[i]=temp;
}
}
後的錯誤消息,並在那裏發生的事情 –
其中後發生錯誤的行號或張貼堆棧跟蹤 – gvmani
爲什麼以書面形式代替不使用Collections.sort()你自己排序? – Tim