小编Zis*_*min的帖子

无法初始化主类,原因为:java.lang.NoClassDefFoundError: com/mashape/unirest/http/exceptions/UnirestException [JAVA]

问题

在 Eclipse 中运行 Maven“编译”、“安装”命令以创建可执行 JAR 并继续运行该 JAR 后,出现以下错误

Error: Unable to initialize main class org.example.project.StockTracker` Caused by: java.lang.NoClassDefFoundError: com/mashape/unirest/http/exceptions/UnirestException

我不知道发生了什么事。我该如何解决这个问题?以下是一些进一步的细节。我使用主类信息更新了 POM,并将类路径设置为“true”。

主类代码

package org.example.project;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class StockTracker {

    public static void main (String[] args) throws UnirestException, InterruptedException  {
        HttpResponse<String> response = Unirest.get("https://apidojo-yahoo-finance-v1.p.rapidapi.com/market/get-quotes?region=US&lang=en&symbols=TSLA")
                    .header("x-rapidapi-host", "apidojo-yahoo-finance-v1.p.rapidapi.com")
                    .header("x-rapidapi-key", "api-key")
                    .asString();

        //System.out.println(response.getBody());
        System.out.println("response.getBody()");
    }
}
Run Code Online (Sandbox Code Playgroud)

UNIREST 异常类代码

package com.mashape.unirest.http.exceptions;

public class UnirestException extends Exception {

    private static final long serialVersionUID = -3714840499934575734L;

    public UnirestException(Exception e) {
        super(e); …
Run Code Online (Sandbox Code Playgroud)

java eclipse noclassdeffounderror maven unirest

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

eclipse ×1

java ×1

maven ×1

noclassdeffounderror ×1

unirest ×1