我遇到了一个错误 java.lang.ArrayIndexOutOfBoundsException: 0
,那么如何避免这个错误呢?
package javaapplication1;
import java.net.*;
import java.io.*;
public class Url {
public static void main(String[] args) {
try {
URL url = new URL(args[0]);
System.out.println("URL is " + url.toString());
System.out.println("protocol is "
+ url.getProtocol());
System.out.println("authority is "
+ url.getAuthority());
System.out.println("file name is " + url.getFile());
System.out.println("host is " + url.getHost());
System.out.println("path is " + url.getPath());
System.out.println("port is " + url.getPort());
System.out.println("default port is "
+ url.getDefaultPort());
System.out.println("query is " + url.getQuery());
System.out.println("ref is " + url.getRef());
} catch (IOException e) {
e.printStackTrace();
}
}
}
错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at javaapplication1.Url.main(Url.java:10) Java Result: 1