简体   繁体   English

应用程序的序列化错误java.io.NotSerializableException:

[英]Error in serialization of the application, java.io.NotSerializableException:

I am trying to run a Vaadin project in google cloud platform using Google Cloud Platform(a plugin in Eclipse). 我正在尝试使用Google Cloud Platform(Eclipse中的插件)在Google Cloud Platform中运行Vaadin项目。 After running in I get this exception: 运行后,我得到这个异常:

WARNING: Error in serialization of the application: Class 
rand.TestProject.AutoCrudView$1 must implement serialization.
2019-03-02 15:54:06.159:WARN:oejs.session:qtp1757676444-19: 
java.io.NotSerializableException: java.lang.ref.WeakReference
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.util.LinkedList.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)

This is the AutoCrudView class: 这是AutoCrudView类:

    @SuppressWarnings("serial")
    public class AutoCrudView  extends Window implements Serializable{
    private static final long serialVersionUID = 1L;

    public AutoCrudView(String PERSISTENCE_UNIT) {
        final HorizontalSplitPanel horizontalSplitPanel = new HorizontalSplitPanel();
        Tree navTree = new Tree();
        navTree.addListener(new Property.ValueChangeListener() {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                @SuppressWarnings("rawtypes")
                BasicCrudView cv = (BasicCrudView) event.getProperty()
                        .getValue();
                cv.refreshContainer();
                horizontalSplitPanel.setSecondComponent(cv);
            }
        });
        navTree.setSelectable(true);
        navTree.setNullSelectionAllowed(false);
        navTree.setImmediate(true);

        horizontalSplitPanel.setSplitPosition(200,
                HorizontalSplitPanel.UNITS_PIXELS);
        horizontalSplitPanel.addComponent(navTree);
        setContent(horizontalSplitPanel);

        // add a basic crud view for all entities known by the JPA
        // implementation, most often this is not desired and developers
        // should just list those entities they want to have editors for
        Metamodel metamodel = JPAContainerFactory
                .createEntityManagerForPersistenceUnit(PERSISTENCE_UNIT)
                .getEntityManagerFactory().getMetamodel();
        Set<EntityType<?>> entities = metamodel.getEntities();
        for (EntityType<?> entityType : entities) {
            Class<?> javaType = entityType.getJavaType();
            @SuppressWarnings({ "rawtypes", "unchecked" })
            BasicCrudView view = new BasicCrudView(javaType,
                    PERSISTENCE_UNIT);
            navTree.addItem(view);
            navTree.setItemCaption(view, view.getCaption());
            navTree.setChildrenAllowed(view, false);
            if(javaType == Person.class) {
                view.setVisibleTableProperties("firstName","lastName", "boss");
                view.setVisibleFormProperties("firstName","lastName", "phoneNumber", "street", "city", "zipCode", "boss");
            }

        }

        // select first entity view
        navTree.setValue(navTree.getItemIds().iterator().next());
    }

    }

As you can see I've implemented Serializable but without sucess. 如您所见,我已经实现了Serializable但没有成功。 This is the image that I got from App Engine window: here 这是我从App Engine窗口获得的图片: 此处

You get that warning about an anonymous inner class (that $1 in the end of class name) not the actual class itself. 您会收到有关匿名内部类(类名末尾的$ 1)而不是实际类本身的警告。

So: go hunting where you (accidentally) create an inner class instance and try to persist that one. 所以:去寻找(偶然地)创建一个内部类实例并尝试持久化该实例的地方。

Maybe that 也许那个

new(...) {

Where you add the change listener to your tree object. 将更改侦听器添加到树对象的位置。 If so, the question would be whether the listener should be a distinct class that should implement that interface. 如果是这样,问题将是,侦听器是否应该是应该实现该接口的不同类。 Or if you are simply doing something wrong by trying to persist something that has such a listener (not being an expert in this framework, I find it suspicious to persist ui elements including listener instances). 或者,如果您只是通过尝试尝试保留具有此类侦听器的某些东西而在做错事(不是该框架的专家,我发现坚持包括侦听器实例的ui元素可疑)。

您可以尝试在单独的文件中声明Property.ValueChangeListener并检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM