java编程,出现线程“main”中出现异常的问题

用idea编写java,出现这种情况
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at yecheng.Search.main(Search.java:18)

Process finished with exit code 1
源代码:
public class Search {
public static void main(String[] arg){
MysqlDB db = new MysqlDB();
Index index = new Index();
ReadFile rf = new ReadFile();
File file = new File(arg[0]);
try {
rf.readFile(file);
index.loadDB(db);
int id = index.search(rf.fingerprint,15);
System.out.println(id);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.toString());
}
}
}

取值时,先看下String[] arg 这个数组里面有没有值,就是做一个判断,一般情况下可能是File file = new File(arg[0]); 这一步出错,就是 arg数组没有值,但是你取了。
加个if判断就行

先看下String[] arg 这个数组里面有没有值

Search.java:18 很明显18行报错了。ArrayIndexOutOfBoundsException 数组越界了。就知道报错原因了。

arg这个数组没值, 但是你进行了取值操作arg[0]了,所以报数组越界一次