我需要有关该计划的帮助。我不断收到运行时发生的错误。如果有人能告诉我是否有任何其他问题,我也希望如此。谢谢!
import java.io.*;
import java.util.*;
public class Lab2 {
private String[][] data;
public void readFile() {
//Instantiate file object
File f = new File("nameslist.txt");
try {
Scanner input = new Scanner(f);
//open file for reading
int x = input.nextInt();
data = new String[x][3];
int i = 0;
while (input.hasNext() && i < data.length) {
String name = input.nextLine();
String[] nameArray = name.split(" ");
data[i][0] = nameArray[0];
data[i][0] = nameArray[1];
data[i][0] = nameArray[2];
i++;
}
input.close();
} catch (IOException e) { //opening failed
e.printStackTrace();
}
}
public void outputNames() {
System.out.println("First Name\tMiddle Name\tLast Name");
for (int i = 0; i < data.length; i++)//output all elements
{
System.out.println(data[i][0] + "\t\t" + data[i][1] + "\t\t" + data[i][2]);
}
}
public int nameSearch( String key) {
for (int i = 0; i < data.length; i++) {
if (key.equalsIgnoreCase(data[i][0])||key.equalsIgnoreCase(data[i][1])||key.equalsIgnoreCase(data[i][2])) {
return i;
}
}
return -1;
}
public void hashCodeMethod() {
long hash = 5381;
for (int i = 0; i < data.length; i++){
long hashCode = 0;
for (int j = 0; j < data[i].length; j++){
for (int k = 0; k < data[i][j].length(); k++){
data[i][j].charAt(i);
hashCode += ((hash << 5) + hash) + data[i][j].charAt(i);
}
}
}
}
}
结束类Lab2
package lab.pkg2;
public class Lab2Client{
public static void main(String[] args) {
Lab2 test = new Lab2();
test.readFile();
test.outputNames();
test.nameSearch("Gamaliel");
test.hashCodeMethod();
}
}
我在运行时收到此错误:
Exception in thread “main” java.lang.RuntimeException:Uncompilable source code -
Erroneous tree type: lab.pkg2.Lab2
答案 0 :(得分:0)
删除NetBeans缓存~/.netbeans/6.9/var/cache/index/
(该文件夹中的所有内容)
为您的版本更改6.9。