动态加载包问题 用obj= Class.forName(“mytest.user”).newInstance(); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试过了,一样提示java.lang.ClassNotFoundException: mytest.user java是大小写敏感的,类名是不是大写开头阿? 那就是你的 mytest.user这个类有问题了,我一直都是这么用的没有问题的! user只是一很简单的用来测试的类,不可能有问题的呀,直接import到工程来一点问题也没有package mytest;public class user{ public user() { } public int add(Integer a,Integer b) { return a.intValue()+b.intValue(); }} void test_load() { Class obj = null; File file = new File("c:\\mytest.jar"); URL url = null; try { url = file.toURL(); } catch (MalformedURLException ex) { ex.printStackTrace(); } URLClassLoader loader = new URLClassLoader(new URL[] {url}); try { obj = (Class) Class.forName("mytest.user").newInstance(); } catch (ClassNotFoundException ex1) { ex1.printStackTrace(); } catch (IllegalAccessException ex1) { } catch (InstantiationException ex1) { } Class partypes[] = new Class[2]; partypes[0] = Integer.TYPE; partypes[1] = Integer.TYPE; java.lang.reflect.Method meth = null; String methname = "add"; try { meth = obj.getMethod(methname, partypes); } catch (SecurityException ex2) { } catch (NoSuchMethodException ex2) { } System.out.println("get the method of the class"); Object arglist[] = new Object[2]; arglist[0] = new Integer(37); arglist[1] = new Integer(47); Object objreturn = null; try { objreturn = meth.invoke(obj, arglist); } catch (InvocationTargetException ex3) { } catch (IllegalArgumentException ex3) { } catch (IllegalAccessException ex3) { } Integer retval = (Integer) objreturn; System.out.println(retval.intValue()); } 基站定位数据是什么东西,长得什么样子,怎么用它获取当前地址 Extjs4.0 treepanel 做日企的外包 倾囊求教:hibernate问题 org.hibernate.WrongClassException,求救!! 英文不好,看API有点不明白 关于java正则表达式解析文本 求助:JCreator中的问题!! 客户端程序怎么调用两个EJB(处于不同的IP地址)? 怎样启动RMI服务 如何把servlet中读取的txt文件内容显示到jsp页面上? 用tomcat连接池 数据库重启后不能自动恢复
java.lang.ClassNotFoundException: mytest.user
package mytest;
public class user
{
public user()
{
} public int add(Integer a,Integer b)
{
return a.intValue()+b.intValue();
}
}
{ Class obj = null;
File file = new File("c:\\mytest.jar");
URL url = null; try {
url = file.toURL();
}
catch (MalformedURLException ex) {
ex.printStackTrace();
} URLClassLoader loader = new URLClassLoader(new URL[] {url}); try {
obj = (Class) Class.forName("mytest.user").newInstance();
}
catch (ClassNotFoundException ex1)
{
ex1.printStackTrace();
}
catch (IllegalAccessException ex1) {
}
catch (InstantiationException ex1) {
} Class partypes[] = new Class[2];
partypes[0] = Integer.TYPE;
partypes[1] = Integer.TYPE;
java.lang.reflect.Method meth = null;
String methname = "add"; try {
meth = obj.getMethod(methname, partypes);
}
catch (SecurityException ex2) {
}
catch (NoSuchMethodException ex2) {
} System.out.println("get the method of the class"); Object arglist[] = new Object[2];
arglist[0] = new Integer(37);
arglist[1] = new Integer(47);
Object objreturn = null; try {
objreturn = meth.invoke(obj, arglist);
}
catch (InvocationTargetException ex3) {
}
catch (IllegalArgumentException ex3) {
}
catch (IllegalAccessException ex3) {
} Integer retval = (Integer) objreturn;
System.out.println(retval.intValue()); }