为什么com.codename1.io.Util.writeObject在UWP上抛出异常而不在模拟器上抛出异常?

时间:2017-05-15 12:54:57

标签: uwp codenameone

我有一个在Android,iOS和Simulator上运行良好的externalize函数,但在我尝试启用的UWP构建上运行它时失败并出现异常。

任何人都可以告诉我这是否正常,我只是不知道有关在UWP上进行外部化的事情,或者如果这是一个错误我们应该打开作为一个问题?

导致它的代码是:

@Override
public void externalize(DataOutputStream out) throws IOException {
    Util.writeUTF(this.modSetVersion, out);
    Util.writeObject(getObjectsArrayFromLinkedHashMap(this.modules),out); //**Exception on this line
    Util.writeObject(getObjectsArrayFromLinkedHashMap(this.categories),out);
    Util.writeObject(this.learnables,out);
}

//Generates an array of objects from a LinkedHashMap to retain order in externalized file
private Object[] getObjectsArrayFromLinkedHashMap(LinkedHashMap lhm) {
    Set set = lhm.entrySet();
    Iterator iterator = set.iterator();
    Object[] objList = new Object[set.size()];
    int i = 0;
    while(iterator.hasNext()) {
        Map.Entry me = (Map.Entry) iterator.next();
        objList[i++] = me.getValue();
    }
    return objList;
}

(请注意,在异常时将外部化的数组中的对象(this.modules)正确地声明为可外部化并包含可外部化的其他对象,但是从堆栈跟踪看来它不会进展到对象在这个可外化的对象失败之前)

从UWP桌面客户端(Windows 10企业版)上捕获的日志进行堆栈跟踪:

[EDT] 0:1:15,155 - Exception: java.io.IOException - Object type not supported: [Ljava.lang.Object; value: [Ljava.lang.Object;@e08d4a

   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at UWPApp.IKVMReflectionHelper.getCurrentStackTrace()
   at java.lang.ThrowableHelper.getCurrentStackTrace()
   at java.lang.Throwable..ctor(String message)
   at java.lang.Exception..ctor(String message)
   at java.io.IOException..ctor(String message)
   at com.codename1.io.Util.writeObject(Object o, DataOutputStream out)
   at trainingtoolDataModel.ModuleSet.externalize(DataOutputStream out)
   at com.codename1.io.Util.writeObject(Object o, DataOutputStream out)
   at com.codename1.io.Storage.writeObject(String name, Object o)
   at userclasses.StateMachine.saveModuleSet(ModuleSet modSet)
   at userclasses.StateMachine.successfullyDownloadedAllAuthorizedContent(String retrievedVersion)
   at userclasses.StateMachine.updateContentFromNetwork(Boolean force)
   at userclasses.StateMachine.loadContentFirstTime(Form f)
   at userclasses.StateMachine.onFirstTimeSetupLogin_ContinueButtonAction(Component c, ActionEvent event)
   at generated.StateMachineBase.handleComponentAction(Component c, ActionEvent event)
   at com.codename1.ui.util.UIBuilder.FormListener.actionPerformed(ActionEvent evt)
   at com.codename1.ui.util.EventDispatcher.fireActionEvent(ActionEvent ev)
   at com.codename1.ui.Button.fireActionEvent(Int32 x, Int32 y)
   at com.codename1.ui.Button.released(Int32 x, Int32 y)
   at com.codename1.ui.Button.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.Form.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.Form.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.Component.pointerReleased(Int32[] x, Int32[] y)
   at com.codename1.ui.Display.handleEvent(Int32 offset)
   at com.codename1.ui.Display.edtLoopImpl()
   at com.codename1.ui.Display.invokeAndBlock(Runnable r, Boolean dropEvents)
   at com.codename1.ui.Display.invokeAndBlock(Runnable r)
   at com.codename1.impl.SilverlightImplementation.editString(Component n1, Int32 n2, Int32 n3, String n4, Int32 n5)
   at com.codename1.impl.CodenameOneImplementation.editStringImpl(Component cmp, Int32 maxSize, Int32 constraint, String text, Int32 initiatingKeycode)
   at com.codename1.ui.Display.editString(Component cmp, Int32 maxSize, Int32 constraint, String text, Int32 initiatingKeycode)
   at com.codename1.ui.Display.editString(Component cmp, Int32 maxSize, Int32 constraint, String text)
   at com.codename1.ui.TextArea.editString()
   at com.codename1.ui.TextArea.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.TextField.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.Form.pointerReleased(Int32 x, Int32 y)
   at com.codename1.ui.Component.pointerReleased(Int32[] x, Int32[] y)
   at com.codename1.ui.Display.handleEvent(Int32 offset)
   at com.codename1.ui.Display.edtLoopImpl()
   at com.codename1.ui.Display.mainEDTLoop()
   at com.codename1.ui.RunnableWrapper.run()
   at com.codename1.impl.CodenameOneThread.run()
   at java.lang.Thread.threadProc2()
   at java.lang.Thread.threadProc()
   at java.lang.Thread.1.Invoke()
   at com.codename1.impl.NativeThreadImpl.<>c__DisplayClass6_0.<init>b__0()
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
   at System.Threading.Tasks.Task.ExecutionContextCallback(Object obj)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.Tasks.ThreadPoolTaskScheduler.LongRunningThreadWork(Object obj)
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart(Object obj)
Originating from:
Message=Object type not supported: [Ljava.lang.Object; value: [Ljava.lang.Object;@e08d4a
   at com.codename1.io.Util.writeObject(Object o, DataOutputStream out)
   at trainingtoolDataModel.ModuleSet.externalize(DataOutputStream out)
   at com.codename1.io.Util.writeObject(Object o, DataOutputStream out)
   at com.codename1.io.Storage.writeObject(String name, Object o)

1 个答案:

答案 0 :(得分:0)

异常意味着不支持其中一个对象类型,但很难分辨出哪一个。

我猜这条线是错的:

    objList[i++] = me.getValue();

我假设由于UWP上的某些不同行为,你在那里获得了不同的对象类型,我建议用你正在编写的所有对象的类名添加日志。