Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“如何排除故障”;java.lang.NumberFormatException:null";_Java_Numberformatexception - Fatal编程技术网

“如何排除故障”;java.lang.NumberFormatException:null";

“如何排除故障”;java.lang.NumberFormatException:null";,java,numberformatexception,Java,Numberformatexception,下面是我用java编写的代码的一部分。我在线路上遇到了一个错误 “c=Integer.parseInt(br.readLine());” 请帮忙 public class decipher { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

下面是我用java编写的代码的一部分。我在线路上遇到了一个错误 “c=Integer.parseInt(br.readLine());” 请帮忙

public class decipher
{
    public static void main (String[] args) throws IOException
    {

        BufferedReader br = new BufferedReader(new 
InputStreamReader(System.in));
        int [][] plainText= new int [16][16];
        int [][] key= new int [16][16];
        int [][] num= new int [16][16];
        int [][] finalKey= new int [16][16];
        int [][] cipherText= new int [16][16];
        int c=0,a=0,i,j,m,n;
        System.out.println("Enter cipher text character by character:");
        for (i=0;i<16;i++)
        {
            for (j=0;j<16;j++)
            {
                c= Integer.parseInt(br.readLine());
                if (c<257)
公共类解密
{
公共静态void main(字符串[]args)引发IOException
{
BufferedReader br=新的BufferedReader(新的
InputStreamReader(System.in));
int[][]纯文本=新int[16][16];
int[][]键=新int[16][16];
int[]num=新int[16][16];
int[]finalKey=新int[16][16];
int[][]密文=新int[16][16];
int c=0,a=0,i,j,m,n;
System.out.println(“逐个字符输入密文:”);
对于(i=0;i
,readLine()返回:

包含行内容的字符串,不包括任何行终止字符,如果在未读取任何字符的情况下到达流的结尾,则为null

因此,您的语句相当于
Integer.parseInt(null)
。这就是为什么存在java.lang.NumberFormatException的原因

您的错误可以通过使用
而不是readLine(),因为您正在获取字符输入。

当缓冲读取器读取的文件中没有更多行时,它将返回
null
。您应该始终检查它。如何检查它?
if((input=reader.readLine())==null)
,或者
input=reader.readLine();if(input=null)