简体   繁体   English

在 Adobe Air 中创建 XML 日志时需要一些帮助

[英]Need some help in creating XML log in Adobe Air

I need to create XML log file in Adobe Air.我需要在 Adobe Air 中创建 XML 日志文件。 My first thought was to use some kind of automated serialization.我的第一个想法是使用某种自动序列化。 And I've found FlexXB library.而且我找到了 FlexXB 库。 I've created simple logger and marked the class with annotations in the following way我创建了简单的记录器并通过以下方式用注释标记了 class

package loggingTools
{

    [XmlClass]
    [ConstructorArg(reference="timeStamp")]
    [ConstructorArg(reference="item")]
    [ConstructorArg(reference="action")]
    [ConstructorArg(reference="arguments")]
    [ConstructorArg(reference="success")]
    [Bindable]
    public class MessageAction
    {
    [XmlAttribute()]
    public var timeStamp:Date;

            [XmlAttribute()]
            public var item:String;

            [XmlAttribute()]
            public var action:String;

            [XmlAttribute()]
            public var arguments:String;

            [XmlAttribute()]
            public var success:Boolean;

            public function MessageAction(timeStamp:Date, item:String, action:String, arguments:String, success:Boolean) {
                    this.timeStamp = timeStamp;
                    this.item = item;
                    this.action = action;
                    this.arguments = arguments;
                    this.success = success;

            }

}

I'm trying to serialize the single object:我正在尝试序列化单个 object:

public class PlainXMLLogger
{
    //private static var isStarted:Boolean;

    private var logFile:XML;

            [XmlArray(alias = "Log", type="loggingTools.MessageAction")]
            [ArrayElementType("loggingTools.MessageAction")]
    public var messages:Array;

    public function addMessageAction(item:String, action:String, arguments:String, success:Boolean):void {
        var newMessageAction:MessageAction;
        newMessageAction = new MessageAction(new Date(), item, action, arguments, success);
        messages.push(newMessageAction);

    }

public function close():void {

        var logXML:XML = FlexXBEngine.instance.serialize(messages);

        trace(">> XML LOG ");
        trace(logXML.toString() );

    }
}

Now, serialization produces an error: TypeError: Error #1009: Cannot access a property or method of a null object reference.现在,序列化会产生错误: TypeError: Error #1009: Cannot access a property or method of a null object reference。 at com.googlecode.flexxb.core::SerializationCore/serialize()在 com.googlecode.flexxb.core::SerializationCore/serialize()

Sure, I can serialize all objects in collection one-by-one, but I consider, that this is a bad idea.当然,我可以一个一个地序列化集合中的所有对象,但我认为,这是一个坏主意。

Here is the answer on my question, provided by creators of FlexXB tool这是我的问题的答案,由 FlexXB 工具的创建者提供

https://groups.google.com/forum/?hl=ru&fromgroups#!topic/flexxb/g912jkxwldE https://groups.google.com/forum/?hl=ru&fromgroups#!topic/flexxb/g912jkxwldE

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

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