Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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 如何在代码中消除这些错误?NumberFormatException:用于输入字符串:“”_Java_Priority Queue_Shortest Path_Minimum Spanning Tree_Kruskals Algorithm - Fatal编程技术网

Java 如何在代码中消除这些错误?NumberFormatException:用于输入字符串:“”

Java 如何在代码中消除这些错误?NumberFormatException:用于输入字符串:“”,java,priority-queue,shortest-path,minimum-spanning-tree,kruskals-algorithm,Java,Priority Queue,Shortest Path,Minimum Spanning Tree,Kruskals Algorithm,当我针对示例输入运行代码时,这些错误会继续弹出。我们得到了一个包含多边形的文档,必须使用kruskal算法并构建一个最小生成树,以在不创建循环的情况下找到到每个岛屿的最短距离。如果有人能提供帮助或建议,如何摆脱这些错误,那将是伟大的!我不明白字符串上怎么会有数字格式异常 Exception in thread "main" java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatExceptio

当我针对示例输入运行代码时,这些错误会继续弹出。我们得到了一个包含多边形的文档,必须使用kruskal算法并构建一个最小生成树,以在不创建循环的情况下找到到每个岛屿的最短距离。如果有人能提供帮助或建议,如何摆脱这些错误,那将是伟大的!我不明白字符串上怎么会有数字格式异常

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at HelloWorld.main(HelloWorld.java:169)
优先队列

public class PriorityQueue {
private Comparable[] HeapArray;
int Last, Limit;
} //端类优先级队列

public PriorityQueue(int Capacity) {
    HeapArray = new Comparable[Capacity + 1];
    Last = 0;
    Limit = Capacity;
    return;
}
// end constructor

public PriorityQueue() {
    HeapArray = new Comparable[101];
    Last = 0;
    Limit = 100;
    return;
}
// end constructor

public void Insert(Comparable PQI) {
    if (Last == Limit) {
        System.out.println("Priority Queue Overflow!");
        System.exit(0);
    }
    // end if

    HeapArray[++Last] = PQI;
    this.UpHeap(Last);
    return;
}
// end public method Insert

private void UpHeap(int k) {
    Comparable V;

    V = HeapArray[k];

    while (k > 1 && HeapArray[k / 2].compareTo(V) < 0) {
        HeapArray[k] = HeapArray[k / 2];
        k = k / 2;
    }
    // end while

    HeapArray[k] = V;
    return;
}
// end private method UpHeap

public Comparable Remove() {
    Comparable PQI;

    if (Last == 0) {
        System.out.println("Priority Queue Underflow!");
        System.exit(0);
    }
    // end if

    PQI = HeapArray[1];
    HeapArray[1] = HeapArray[Last--];
    this.DownHeap(1);
    return PQI;
}
// end public method Remove

private void DownHeap(int k) {
    Comparable V;
    int j;

    V = HeapArray[k];

    while (k <= Last / 2) {
        j = k + k;

        if (j < Last && HeapArray[j].compareTo(HeapArray[j + 1]) < 0)
            j++;
        // end if

        if (V.compareTo(HeapArray[j]) >= 0)
            break;
        // end if

        HeapArray[k] = HeapArray[j];
        k = j;
    }
    // end while

    HeapArray[k] = V;
    return;
}
// end private method DownHeap

public boolean IsEmpty() {
    if (Last == 0)
        return true;
    else
        return false;
    // end if
}
// end public method IsEmpty

public boolean IsFull() {
    if (Last == Limit)
        return true;
    else
        return false;
    // end if
}
// end public method IsFull

public int Length() {
    return Last;
}
// end public method Length
这是不言自明的。输入应为数字,但输入为字符串

读取输入并期望值为整数的行:

Exception in thread "main" java.lang.NumberFormatException: For input string: ""
提供正确的输入。
此外,您还可以将.nextLine更改为nextInt

,因此我应该将nextLine更改为nextInt???@csgirl在您以INTEGER身份输入正确的输入后,它是否工作?我将其更改为nextInt,但仍然出现错误。我不知道你输入修正值是什么意思,因为我在读文件。如果我不知道输入是什么,如何更改输入文件的第一个字段是否为整数值?您能粘贴文件中的前几行吗?上述程序的第169行是否仍有错误?调试代码时,请创建一个。这通常会让您快速发现问题。
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
 int numberOfIslands = Integer.parseInt(fileScanner.nextLine());