RMI JavaFX 2 - NotSerializableException error

落爺英雄遲暮 提交于 2019-12-04 16:59:01

the class being sent via RMI is serializable

It's only serializable if it extends Serializable or Externalizable and all of its non-static non-transient member variables do so as well, and so on recursively until closure. In this case you clearly have one of type javafx.beans.property.SimpleIntegerProperty, which as the exception tells you isn't serializable:

java.io.NotSerializableException: javafx.beans.property.SimpleIntegerProperty

So any class that refers to it, directly or indirectly, isn't serializable either.

You may mark a member variable not to be serialized. And add to class new int field.

private int variableInt = 0;

private transient IntegerProperty variable;

public IntegerProperty variableProperty()
{
    if(variable == null)
    {
        variable = new SimpleIntegerProperty();
        variable.set(variableInt);
    }
    return variable;
}

public void setVariable(int variable)
{
    if(this.variable != null)
        this.variable.set(variable);
    variableInt = variable;
}

public int getVariable()
{
    if(variable == null)
        return variableInt;
    else
        return variable.get();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!