2 winter wind winter_wind 于 2016.02.02 19:18 提问

初学java程序运行异常

第一个文件StaticMain.java
public class StaticMain{
public static void main(String[] args){
System.out.println("-------------");
for(String arg:args){
System.out.println(arg);
}
}
}
第二个文件StaticMainRef.java
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
public class StaticMainRef{
public static void main(String[] args) throws SecurityException,IllegalArgumentException,NoSuchMethodException,ClassNotFoundException,IllegalAccessException,InvocationTargetException{
StaticMain.main(new String[]{"111","222","333","444"});
startClass("com.cjg.method.StaticMain");
}
public static void startClass(String className) throws SecurityException,NoSuchMethodException,ClassNotFoundException,IllegalArgumentException,IllegalAccessException,InvocationTargetException{
Method mainMethod=Class.forName(className).getMethod("main",String[].class);
mainMethod.invoke(null,new Object[]{new String[]{"111","222","333","444"}});
mainMethod.invoke(null,(Object)new String[]{"111","222","333","444"});
}
}
运行后异常
图片说明

1个回答

wwwsssaaaddd
wwwsssaaaddd   2016.02.02 19:24

找不到com/cjg/method/StaticMain这个class文件,请确认它是否在class path里。没有的话 在执行java命令的时候用 -cp + 该class所在路径指定位置

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!