0

尝试运行此代码时出现以下错误:

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 文件运行相同的代码没有问题......

4

1 回答 1

1

好吧,您get似乎返回了NullPointerException.

at com.jayway.restassured.RestAssured.get(RestAssured.java:776)

这个方法内部出了点问题。

如说明中所述,您可能错过了第三方依赖项。加载其他类时似乎弹出错误。

非 Maven 用户

下载 REST Assured 并将其放入您的类路径中。您可能还需要下载第三方依赖项并将它们也放入您的类路径中。

于 2012-10-18T19:11:26.937 回答