动态加载包问题 用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()); } UploadForm上传一个form中的多个file 请教 如何根据日期和天数,返回日期 servlet问题 昨天项目还能跑通,今天就不行啦 各位高人帮忙解决一个问题。 tomcat 怎样导入? 请大家谈谈 webwork 和 stucts 各自的优势? 在JBuilder8+Weblogic7 ReDeploy的奇怪问题! 关于jsp做客户端调用ejb的问题?????望各位兄弟们救救我吧!!!!! 请问一下最近流行的推送技术是怎么实现的? 如何把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()); }