我在Integer.parseInt()方法上收到NumberFormatException。我知道将类似“ ab”的东西传递给该方法时会产生此异常,但我不知所措。
我怎样才能解决这个问题?

我正在使用Netbeans并尝试调试将手表放在caseStartLineSplitted[0]变量上,然后按f7键,但是代码通过了诸如Arrays类之类的东西,我不在乎。如何使它直接进入caseStartLineSplitted[0]更改的地方?

输入文件为:

2
3 2 1
ab
1 0
2 0
2 0
2
0 3
abaa
aab
aba
3 3 2
ade
0 1 2
1 2 0
2 1 0
1 2
2 2
a
de



 /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package afd;

    import java.io.*;
import java.util.*;

/**
 *
 * @author Administrator
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here

        FileReader fr = new FileReader("E://Documents and Settings//Administrator//My Documents//NetBeansProjects//AFD//src//afd//dfa.in");


        BufferedReader br = new BufferedReader(fr);

        String firstLine= br.readLine();


        String [] firstLineSplitted = firstLine.split(" ");

        /*debug*/
        System.out.println(firstLine);

        int numberOfTestCases = Integer.parseInt(firstLine);

        for (int indexOfTestCases =0; indexOfTestCases < numberOfTestCases; indexOfTestCases++  ){

            String caseStartLine = br.readLine();

            /*debug*/
            System.out.println(caseStartLine);
            String [] caseStartLineSplitted = caseStartLine.split("");

            int numberOfStates = Integer.parseInt(caseStartLineSplitted[0]);

            int numberOfAlphabetSymbols = Integer.parseInt(caseStartLineSplitted[1]);

            //int numberOfFinalStates = Integer.parseInt(caseStartLineSplitted[2]);

            String alphabetLine = br.readLine();

            for (int indexOfStates = 0; indexOfStates < numberOfStates; indexOfStates++){

                  String ijLine = br.readLine();
                  String [] ijLineSplitted = ijLine.split(" ");

                  int i = Integer.parseInt(ijLineSplitted[0]);
                  int j = Integer.parseInt(ijLineSplitted[1]);


            }

            String finalStatesLine = br.readLine();
            String finalStatesLineSplitted [] = finalStatesLine.split(" ");
            ArrayList<Integer> finalStates = new ArrayList<Integer>();

            for (int conversionIndex =0; conversionIndex < finalStatesLineSplitted.length; )

            }

         }
        }

最佳答案

我认为您的错误是此行上缺少空格:

String[] caseStartLineSplitted = caseStartLine.split(" ");


你写了:

String[] caseStartLineSplitted = caseStartLine.split("");


当我更改时,我得到以下输出,没有错误:

2
3 2 1
0 3

关于java - 杀死此NumberFormatException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1869948/

10-11 20:43