Java 杀死这个数字形式异常
我在Integer.parseInt方法上得到一个NumberFormatException。我知道当ab之类的东西被传递给方法时会产生这个异常,但我无法找到发生这种情况的地方。 我怎样才能解决这个问题 我正在使用Netbeans并尝试调试caseStartIneSplitted[0]变量,然后点击f7,但是代码会经历一些事情,比如Arrays类,我不关心这些。如何使其直接转到CaseStartInEssplited[0]发生更改的位置 输入文件为:Java 杀死这个数字形式异常,java,netbeans,Java,Netbeans,我在Integer.parseInt方法上得到一个NumberFormatException。我知道当ab之类的东西被传递给方法时会产生这个异常,但我无法找到发生这种情况的地方。 我怎样才能解决这个问题 我正在使用Netbeans并尝试调试caseStartIneSplitted[0]变量,然后点击f7,但是代码会经历一些事情,比如Arrays类,我不关心这些。如何使其直接转到CaseStartInEssplited[0]发生更改的位置 输入文件为: 2 3 2 1 ab 1 0 2 0 2 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; )
}
}
}
为什么不用try/catch NumberFormatException来包围整个区块,并以这种方式处理呢?您不需要是细粒度的,因为如果一行中的任何地方都有字母,那么该行是无效的,您可以继续前进。为什么不用try/catch NumberFormatException环绕整个块,并以这种方式处理它呢?您不需要是细粒度的,因为如果一行中的任何位置都有字母,那么该行无效,您可以继续前进。尝试从开始使用断点
String [] caseStartLineSplitted = caseStartLine.split("");
然后使用F8上的单步执行尝试使用从
String [] caseStartLineSplitted = caseStartLine.split("");
使用F8上的单步执行,我认为您的错误是这一行缺少空格:
String[] caseStartLineSplitted = caseStartLine.split(" ");
你写道:
String[] caseStartLineSplitted = caseStartLine.split("");
当我更改该值时,我将获得以下输出,没有错误:
2
3 2 1
0 3
我认为你的错误是这行缺少一个空格:
String[] caseStartLineSplitted = caseStartLine.split(" ");
你写道:
String[] caseStartLineSplitted = caseStartLine.split("");
当我更改该值时,我将获得以下输出,没有错误:
2
3 2 1
0 3
您还可以使用ScannerString而不是split,然后使用hasNext、hasNextInt和nextInt。您还可以使用ScannerString而不是split,然后使用hasNext、hasNextInt和nextInt