2016-08-26 1 views
0
 for(int i=0;i<=5;i++){ 
      HtmlPage currentPage = (HtmlPage)client.getPage("http:// http://testsite.com "); 
      HtmlForm form = (HtmlForm) currentPage.getElementById("kelimeAraID"); 
      HtmlButton button = (HtmlButton) form.getElementsByTagName("button").get(0); 
      HtmlTextInput kullaniciAdi= form.getInputByName("kelime"); 
      kullaniciAdi.setText(arrayList.get(i)); 
      HtmlPage sayfa2= button.click(); 
      HtmlTableRow tr=(HtmlTableRow)sayfa2.getFirstByXPath("//*[@id=\"hor-minimalist-a\"]/tbody/tr[1]"); 
      System.out.println(arrayList.get(i)+":"+tr.asText()); /*line:95*/ 
      client.closeAllWindows(); 
     } 

Exception dans le thread "principal" java.lang.NullPointerException à htmlunit.HtmlUnit.main (HtmlUnit.java:95)java bouton HtmlUnit clic ne marche pas pour travailler dans le retour de la boucle NullPointerException

Répondre

0

Cela signifie probablement que arrayList est plus courte que 6 dans le cas d'erreur.

Essayez ceci:

if(i < arrayList.size()){ 
    System.out.println(arrayList.get(i)+":"+tr.asText()); 
}else { 
    System.out.println("XXX":"+tr.asText()); 
} 
+0

grâce à l'aide, mais cette raison d'exception n'est pas Arraylist, return null "tr". – alidogan