1

我正在尝试在我的android应用程序中使用cloudsight.ai api,使用来自url的图像,来自mashape平台的cloudsight.ai api

当我构建应用程序时没有问题,但是当我运行它并单击按钮时它崩溃了。

这是使用 unirest 库的请求代码:

        try {
        HttpResponse<JsonNode> sent = Unirest.post("https://camfind.p.mashape.com/image_requests")
                .header("X-Mashape-Key", "key")
                .header("Content-Type", "application/x-www-form-urlencoded")
                .header("Accept", "application/json")
                .field("image_request[language]", "en")
                .field("image_request[locale]", "en_US")
                .field("image_request[remote_image_url]", img)
                .asJson();
        req_body=sent.getBody().toString();
    } catch (UnirestException e) {

    }

这里是响应代码:

try {
        JSONObject json = new JSONObject(req_body);
        token = json.getString("token");
    } catch (JSONException e) {

    }

    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {

    }
    String res_path = "https://camfind.p.mashape.com/image_responses/" + token;
    try {
        HttpResponse<JsonNode> response = Unirest
                .get(res_path)
                .header("X-Mashape-Key", "key")
                .header("Accept", "application/json")
                .asJson();
        result=response.getBody().toString();
    } catch (UnirestException e) {

    }
    Toast.makeText(Main3Activity.this,result,Toast.LENGTH_SHORT).show();
}

如何解决这个问题呢?

4

1 回答 1

1

NoSuchFieldError如果应用程序尝试访问或修改对象的指定字段,并且该对象不再具有该字段,则会引发。通常,这个错误会被编译器捕获;如果类的定义发生了不兼容的更改,则此错误只会在运行时发生。大多数情况下,它发生在您的应用程序尚未完全编译或您编译正常但后来更改了一些尚未编译的引用时。

您可以通过清理所有项目文件并使用清理和构建菜单项从头开始重新构建它们来解决此问题。

于 2017-12-12T01:46:00.450 回答