标题: LR java vuser 空指针异常 [打印本页] 作者: zbzbzb022 时间: 2010-6-28 16:29 标题: LR java vuser 空指针异常 我用java写了一个远程调用的程序,通过url携带参数的方式访问远程服务器,以获取服务器的响应,在eclipse下编译通过也能正常访问远程服务器了。我把编译好的包含绝对路径的Class文件放到虚拟用户目录下,有三个需要的第三方jar包,我也同样放到了虚拟用户的目录下了。使用如下代码进行调用。
import lrapi.lr;
import com.lt.test.*;
import com.lt.testauth.*;
public class Actions
{
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
lr.rendezvous("申请任务!");
new AuthUtil().main((String[])null);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
可是为什么会报出空指针异常呢?异常信息如下:
Virtual User Script started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
Rendezvous 申请任务!
Error: System.err: java.lang.ExceptionInInitializerError Error
System.err: at com.lt.testauth.AuthUtil.authtoken(AuthUtil.java:25) Error
System.err: at com.lt.testauth.AuthUtil.main(AuthUtil.java:78) Error
System.err: at Actions.action(Actions.java:21) Error
Error: System.err: Caused by: java.lang.NullPointerException Error
System.err: at sun.misc.URLClassPath$3.run(URLClassPath.java:323) Error
System.err: at java.security.AccessController.doPrivileged(Native Method) Error
System.err: at sun.misc.URLClassPath.getLoader(URLClassPath.java:320) Error
System.err: at sun.misc.URLClassPath.getLoader(URLClassPath.java:297) Error
System.err: at sun.misc.URLClassPath.findResource(URLClassPath.java:144) Error
System.err: at java.net.URLClassLoader$2.run(URLClassLoader.java:362) Error
System.err: at java.security.AccessController.doPrivileged(Native Method) Error
System.err: at java.net.URLClassLoader.findResource(URLClassLoader.java:359) Error
System.err: at java.lang.ClassLoader.getResource(ClassLoader.java:978) Error
System.err: at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1168) Error
System.err: at org.apache.commons.logging.LogFactory$3.run(LogFactory.java:597) Error
System.err: at java.security.AccessController.doPrivileged(Native Method) Error
System.err: at org.apache.commons.logging.LogFactory.getResourceAsStream(LogFactory.java:593) Error
System.err: at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:237) Error
System.err: at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351) Error
System.err: at org.apache.commons.httpclient.HttpMethodBase.<clinit>(HttpMethodBase.java:104) Error
System.err: ... 3 more Error
Error: java.lang.ExceptionInInitializerError
Error: at com.lt.testauth.AuthUtil.authtoken(AuthUtil.java:25)
at com.lt.testauth.AuthUtil.main(AuthUtil.java:78)
at Actions.action(Actions.java:21)
Caused by: java.lang.NullPointerException
at sun.misc.URLClassPath$3.run(URLClassPath.java:323)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:320)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:297)
at sun.misc.URLClassPath.findResource(URLClassPath.java:144)
at java.net.URLClassLoader$2.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findResource(URLClassLoader.java:359)
at java.lang.ClassLoader.getResource(ClassLoader.java:978)
at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1168)
at org.apache.commons.logging.LogFactory$3.run(LogFactory.java:597)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.commons.logging.LogFactory.getResourceAsStream(LogFactory.java:593)
at org.apache.commons.logging.LogFactory.getFactory(LogFactory.java:237)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:351)
at org.apache.commons.httpclient.HttpMethodBase.<clinit>(HttpMethodBase.java:104)
Abort was called from an action.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.作者: zbzbzb022 时间: 2010-6-28 16:31
大家帮忙看看啊,我是新手啊,什么都不懂啊!作者: yinxiaodan 时间: 2010-7-8 20:36
是不是少了什么外部文件没有拷贝到脚本目录下作者: 泊涯 时间: 2010-7-9 19:28
是不是有JAR 包没有加载进去
或者你系统环境变量没设置对作者: msnshow 时间: 2010-7-16 20:48
初始化就失败了,应该是少了需要的包作者: iewgku 时间: 2010-10-9 10:50
请问楼主的问题解决了吗?我也碰到这个问题.不知从何下手.在其它开发工具中都能成功运行.但是在LR中就报错了.作者: lilye974 时间: 2012-3-2 16:47
同问,现在到底解决了没有。作者: 随风而动 时间: 2012-6-13 12:45
有解决办法没啊???作者: 金小言 时间: 2014-6-6 16:49
重新导入jar包以及Class文件作者: yetties2005 时间: 2014-9-29 17:17
JAR包要放在项目中,运行LoadRunner前要先编译作者: Frankwangyifang 时间: 2014-11-28 16:54