【问题标题】:Class could not be found error找不到类错误
【发布时间】:2016-07-03 02:29:49
【问题描述】:

尽我所能尝试解决我的问题,但不在这里发布问题。然而,valadoc 搜索系统最近被破坏了,#vala IRC 频道对 Genie 代码的帮助不大(可以理解)。

目标

我正在尝试提供从 this question 到 this 早期 pandoc gui 应用程序的 OOP Gtk 接口。

问题

我在编译时遇到了错误pandoc-gui.gs:56.24-56.43: error: The type name `DocumentFileSelector' could not be found\n _document_selector:DocumentFileSelector。该类稍后在程序中定义,但我似乎找不到我做错了什么导致它对 init 不可见。

这是初始化例程:

init
    Intl.setlocale()
    Gtk.init (ref args)

    var header = new Header ( "Pandoc GUI" )
    var body = new WorkingFile(  )
    var app = new AppWindow ( header,body )
    var load_new_content_command = new Load( body, document_selector )
    var document_selector = new DocumentFileSelector( app )
    var convert_command = new Convert (document_selector)

    header.add_item( new OpenButton( load_new_content_command ) )
    header.add_item( new ConvertButton ( convert_command ) )

    app.show_all ()
    Gtk.main ()

这是转换类:

class Convert:Object implements Command

    _document_selector:DocumentFileSelector

    construct ( document_selector:DocumentFileSelector )

        _document_selector = document_selector

    def execute()

        var a = new ToPDF()
        a.convert.begin( document_selector.whichFile(), "output_file.pdf" )

还有接口:

interface Command:Object
        def abstract execute()

interface DocumentSelector:Object
        def abstract select():bool
        def abstract get_document():string

还有 DocumentFileSelector 类:

class DocumentFileSelector:Object implements DocumentSelector

    _parent:Window
    _uri:string = ""
    _filename:string = ""

    construct( parent:Window )
        _parent = parent

    def select():bool
        var dialog = new FileChooserDialog( "Open file",
                                        _parent,
                                        FileChooserAction.OPEN,
                                        dgettext( "gtk30", "_OK"),
                                        ResponseType.ACCEPT,
                                        dgettext( "gtk30", "_Cancel" ),
                                        ResponseType.CANCEL)

        selected:bool = false
        var response = dialog.run()
        case response
            when ResponseType.ACCEPT
                    _filename = dialog.get_filename()
                    _uri = dialog.get_uri()
                    selected = true
        dialog.destroy()
        return selected

    def whichFile():string
        return _uri

    def get_document():string
        text : string
        len : size_t
        try
                FileUtils.get_contents (_filename, out text, out len)
        except ex : FileError
                print "%s\n", ex.message
        return text

问题

为什么在这种情况下,init 看不到 DocumentFileSelector?

注意:我仍在研究如何编写一个最低限度可重现的问题,但是当涉及到所有相互依赖的部分的 OOP 时,它并不像听起来那么简单。出于这个原因,这里是整个code,以防我提供的内容不足以提供帮助。

【问题讨论】:

    标签: genie


    【解决方案1】:

    很遗憾,您在 Genie 解析器中遇到了一个错误。您的代码中有三个地方使用两个缩进来指示一个新的代码块。它们是:

    1. 您的接口定义
    2. DocumentFileSelectorselect() 方法中的case when ...
    3. DocumentFileSelectorget_document() 方法中的try...except

    例如,改变

    interface Command:Object
            def abstract execute()
    

    interface Command:Object
        def abstract execute()
    

    一旦你修复了这些,你会在代码中遇到许多其他类型的错误,但你应该能够从 Genie 错误消息中找出如何修复这些错误。

    Genie 解析器正在读取两个缩进,但由于它不保存记录而感到困惑,它正在寻找两个缩进来标记块的结尾。任何想要解决这个问题的人都可以查看Developing Genie

    【讨论】:

      猜你喜欢
      • 2017-05-21
      • 2012-04-18
      • 2019-01-05
      • 2015-06-20
      • 2013-07-18
      • 2023-04-05
      • 2018-12-19
      • 2015-01-11
      • 1970-01-01
      相关资源
      最近更新 更多