首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >严重:未处理的JavaFX + Vert.x + REST异常

严重:未处理的JavaFX + Vert.x + REST异常
EN

Stack Overflow用户
提问于 2020-09-19 10:35:57
回答 2查看 741关注 0票数 0

情况:我更新了我的IDE (Eclipse 2020-6到2020-9),对我的web服务的请求因以下错误停止工作:

代码语言:javascript
复制
sep. 19, 2020 7:09:23 A. M. io.vertx.core.impl.ContextImpl
SEVERE: Unhandled exception
java.lang.NullPointerException
    at model.Concepto.<init>(Concepto.java:23)
    at consumer.ConceptoAccess.lambda$getConceptos$0(ConceptoAccess.java:31)
    at java.base/java.lang.Iterable.forEach(Iterable.java:75)
    at consumer.ConceptoAccess.lambda$getConceptos$1(ConceptoAccess.java:28)
    at io.vertx.ext.web.client.impl.HttpContext.handleDispatchResponse(HttpContext.java:313)
    at io.vertx.ext.web.client.impl.HttpContext.execute(HttpContext.java:300)
    at io.vertx.ext.web.client.impl.HttpContext.next(HttpContext.java:275)
    at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:69)
    at io.vertx.ext.web.client.impl.predicate.PredicateInterceptor.handle(PredicateInterceptor.java:32)

这是我的第23行在Concepto.java中的包“模型”:

代码语言:javascript
复制
package model;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;

public class Concepto {
    
    private IntegerProperty idconcepto;
    private StringProperty descripcion;
    
    public Concepto() {
//      idconcepto = new SimpleIntegerProperty();
        descripcion = new SimpleStringProperty();
    }

    public Concepto(Integer idconcepto, String descripcion) {
//      this.idconcepto.set(idconcepto);
        this.descripcion.set(descripcion);
    }
    
    public Concepto(String descripcion) {
        this.descripcion.set(descripcion);     //<----- Line 23
    }

    public StringProperty getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion.set(descripcion);
    }

    public IntegerProperty getIdconcepto() {
        return idconcepto;
    }
    
}

这是“”包中ConceptoAccess.java中的第31行

代码语言:javascript
复制
public class ConceptoAccess {
    
    private static final String HOST = "192.168.0.15";
    private static final int PORT = 8091;
    
    public static void getConceptos(ObservableList<Concepto> conceptoData) {
        WebClient client = WebClient.create(Vertx.vertx());
        client
        .get(PORT, HOST, "/api/conceptos")
        .send(ar -> {
            if (ar.succeeded()) {
                conceptoData.clear();
                HttpResponse<Buffer> response = ar.result();
                response.bodyAsJsonArray().forEach(concepto -> {
                    JsonObject jo = (JsonObject) concepto;
                    conceptoData.add(new Concepto(jo.getString("descripcion")));     <---Line 31
                });
                System.out.println("Received response with status code " + response.statusCode());
                System.out.println(response.bodyAsJsonArray());
            } else {
                System.out.println("Something went wrong " + ar.cause().getMessage());
            }
        });
    }

我测试了web服务并运行良好:用邮差测试

怎么了?在Eclipse更新之前,一切正常。我使用openJDK 11 + JavaFX 14 +Vert.x3.9.3

蒂娅需要任何帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-09-19 11:53:13

或者把它移到

代码语言:javascript
复制
private final StringProperty descripcion = new SimpleStringProperty();

让它最终结束。删除此初始化器的所有其他出现。

票数 1
EN

Stack Overflow用户

发布于 2020-09-19 11:17:50

您得到一个NullPointerException,因为您试图访问this.description.set,但是this.description是空的。您只在默认构造函数中为描述符提供一个值(参数为零),并在其他构造函数中将其保留为null。

代码语言:javascript
复制
private StringProperty descripcion;

public Concepto() {
    descripcion = new SimpleStringProperty();
}

public Concepto(Integer idconcepto, String descripcion) {
    descripcion = new SimpleStringProperty(); // add this
    this.descripcion.set(descripcion);
}

public Concepto(String descripcion) {
    descripcion = new SimpleStringProperty(); // add this
    this.descripcion.set(descripcion);
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63967792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档