尝试运行此代码时出现以下错误:
import com.jayway.restassured.response.Response;
import static com.jayway.restassured.RestAssured.*;
public class TestRestAssured {
public static void main (String args[]){
// Call the REST service
Response res = get("http://10.213.75.170:5000/bla"); // <--- Crashes on this line.
// Get the JSON payload
String json = res.asString();
}
}
java.lang.NullPointerException
at org.codehaus.groovy.reflection.GeneratedMetaMethod$DgmMethodRecord.loadDgmInfo(GeneratedMetaMethod.java:163)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:155)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:83)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.<init>(MetaClassRegistryImpl.java:61)
at groovy.lang.GroovySystem.<clinit>(GroovySystem.java:29)
at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:49)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.createMap(ScriptBytecodeAdapter.java:619)
at com.jayway.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:336)
at TestRestAssured.main(TestRestAssured.java:16)
Exception in thread "main" java.lang.NullPointerException
at org.codehaus.groovy.runtime.callsite.CallSiteClassLoader.loadClass(CallSiteClassLoader.java:45)
at java.lang.ClassLoader.loadClass(Unknown Source)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.loadClass(ClassLoaderForClassArtifacts.java:58)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.define(ClassLoaderForClassArtifacts.java:42)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:86)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts$1.run(ClassLoaderForClassArtifacts.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.reflection.ClassLoaderForClassArtifacts.defineClassAndGetConstructor(ClassLoaderForClassArtifacts.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteGenerator.compilePojoMethod(CallSiteGenerator.java:229)
at org.codehaus.groovy.reflection.CachedMethod.createPojoMetaMethodSite(CachedMethod.java:257)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.createCachedMethodSite(PojoMetaMethodSite.java:159)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.createPojoMetaMethodSite(PojoMetaMethodSite.java:148)
at groovy.lang.MetaClassImpl.createPojoCallSite(MetaClassImpl.java:3015)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createPojoSite(CallSiteArray.java:116)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:150)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.jayway.restassured.internal.ResponseParserRegistrar.<init>(ResponseParserRegistrar.groovy:42)
at com.jayway.restassured.RestAssured.createTestSpecification(RestAssured.java:1094)
at com.jayway.restassured.RestAssured.given(RestAssured.java:746)
at com.jayway.restassured.RestAssured.get(RestAssured.java:776)
at TestRestAssured.main(TestRestAssured.java:16)
我正在使用休息的1.7,groovy 1.8.8,所有可靠的依赖项都加载到我的系统库路径中。我也在使用jdk 1.7。这是某种环境问题,作为一个同事,使用相同的.jar文件运行相同的代码没问题...
答案 0 :(得分:1)
您的get
似乎已返回NullPointerException
。
at com.jayway.restassured.RestAssured.get(RestAssured.java:776)
此方法内部出现问题。
您可能错过了instructions中提到的第三方依赖项。加载其他类似乎会弹出错误。
非maven用户
下载REST Assured并将其放入您的类路径中。您可能还需要下载第三方依赖项并将它们放在类路径中。