java - Number format exception when trying to read text between span in Selenium -


image
i trying read numbers in brackets '()' using selenium

the html code

<span class="refinement-count"> (14)</span> 

i trying read numbers between span.

using selenium, values in brackets stored in string. after reading values, want add these values. used split function , parsed integer integer.parseint() throwing following exception:

exception in thread "main" java.lang.numberformatexception: input string: ""

here code:

public static void convert(string s){      int sum=0;      string str[]=s.split("[()]+");      int[] numbers=new int[str.length];       (int = 0; < str.length; i++)      {    //system.out.println(str[i]);  --checked here, printing normal integers            numbers[i]=integer.parseint(str[i].trim());           sum=sum+numbers[i];      }      system.out.println("the sum of products "+sum); } 

using try-catch() block exception can caught output not desirable.

modified

when starting loop 1, printing/output

 sum of products 14  sum of products 8  sum of products 8  sum of products 6  sum of products 4  sum of products 3  sum of products 2  sum of products 2  sum of products 1  sum of products 1  sum of products 1  sum of products 1  sum of products 1  sum of products 1  sum of products 1   

still there sum not working

it seems everyones comment correct, why dont avoid such case doing following:

 (int = 0; < str.length; i++)  {    //system.out.println(str[i]);  --checked her, printing normal integers       string numstr = str[i].trim();       if(numstr != "")       {           numbers[i]=integer.parseint(numstr);           sum=sum+numbers[i];       }  }  system.out.println("the sum of products "+sum); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -