首页 > 解决方案 > 在加特林中,出现“线程“主”java.lang.ExceptionInInitializerError 中的异常”错误

问题描述

当我在 scala 目录下运行 Engine.scala 时,它给出了一个错误:

 Exception in thread "main" java.lang.ExceptionInInitializerError
    at Engine$.delayedEndpoint$Engine$1(Engine.scala:7)
    at Engine$delayedInit$body.apply(Engine.scala:4)
    at scala.Function0.apply$mcV$sp(Function0.scala:34)
    at scala.Function0.apply$mcV$sp$(Function0.scala:34)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.immutable.List.foreach(List.scala:389)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at Engine$.main(Engine.scala:4)
    at Engine.main(Engine.scala)
Caused by: java.lang.NullPointerException
    at io.gatling.commons.util.PathHelper$.url2path(PathHelper.scala:34)
    at IDEPathHelper$.<init>(IDEPathHelper.scala:7)
    at IDEPathHelper$.<clinit>(IDEPathHelper.scala)
    ... 11 more

而BaiduHomePageSimulation.scala是:

package test.scala

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class BaiduSimulation extends Simulation {
    // Set the root path of the request
    val httpConf = http.baseUrl("https://www.baidu.com")
    /*
    run 10 seconds, during:the default unit is seconds, if you want to use microseconds eg. during(100 millisecond)
    */
    val scn = scenario("BaiduSimulation").during(10){
        exec(http("baidu_home").get("/"))
    }
    // set the thread count
    setUp(scn.inject(atOnceUsers(10)).protocols(httpConf))
}

不知道怎么解决?有没有人遇到过类似的问题?

标签: gatling

解决方案


我收到了这个错误,并且能够通过将 scala 目录标记为 Test Sources Root 来解决它

右键单击 scala 文件夹 > 将目录标记为 > 测试源根目录


推荐阅读