package cn.dan.day2;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class TestMain {
/**
* @param args
* @throws ClassNotFoundException
* @throws NoSuchMethodException
* @throws SecurityException
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
public static void main(String[] args) throws SecurityException, NoSuchMethodException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
// TODO Auto-generated method stub
String startClassName = args[0] ;
Method mainMethod = Class.forName(startClassName).getMethod("main", String[].class) ;
mainMethod.invoke(null, new Object[]{new String[]{"aaa","bbb","ccc"}}) ;
}
}
class TestArguments{
public static void main(String[] args){
for(String arg : args){
System.out.println(arg);
}
}
}
问题:这个代码为什么会报:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at cn.dan.day2.TestMain.main(TestMain.java:20)
的错误?要怎么样解决?
|
|