String to int给出了nullpointerexception

chu*_*ley 1 java string int

当我运行此代码时,字符串转换为int是否打印出NULL?当我打印出字符串时,它给了我一个字符串编号,但当我尝试将该字符串转换为int时,它表示null,为什么会这样?

for(int j = 0; j < removetrack.size(); j++){
   String removetrackArray[] = removetrack.get(j).split(" ");
   String candidateBefore = "";
   int removetracklocation = Arrays.asList(removetrackArray).indexOf(past)-1;

   if(removetracklocation != 1) {
      String candidateBefore = "";
      System.out.println(removetrack.get(j)+" location =  "+ removetracklocation +" "+ 
         (past)+" candidate name "+dictionary.get(votedfor) );
      candidateBefore= Arrays.asList(removetrackArray).get(removetracklocation+1);
      System.out.println(" this is a string "+candidateBefore);
      System.out.println( Integer.getInteger(candidateBefore));                         
   }    
}
Run Code Online (Sandbox Code Playgroud)

hal*_*dan 8

Integer.getInteger不会将您的字符串转换为int,int返回系统属性的值(请参阅http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Integer.html# getInteger(java.lang.String)).您应该使用Integer.parseInt.