简体   繁体   English

从Elixir调用:wxFrame.new时发生FunctionClauseError

[英]FunctionClauseError when calling :wxFrame.new from Elixir

I have just two questions :) 我只有两个问题:)

  1. What's wrong? 怎么了?
  2. How do I understand what's wrong without asking on Stackoverflow? 我如何不问Stackoverflow而了解出了什么问题?

Elixir code: 药剂代码:

import WxConstants
...
wx = :wx.new
frame = :wxFrame.new(wx, wxID_ANY, "Game of Life", size: {500, 500})

Output: 输出:

** (FunctionClauseError) no function clause matching in :wxFrame.new/4
    gen/wxFrame.erl:111: :wxFrame.new({:wx_ref, 0, :wx, []}, -1, "Game of Life", [size: {500, 500}])

WxConstants module: https://github.com/ElixirWin/wxElixir WxConstants模块: https : //github.com/ElixirWin/wxElixir

Dogbert had already answered the first question, I would answer the second one. Dogbert已经回答了第一个问题,我会回答第二个问题。

** (FunctionClauseError) no function clause matching in ... **(FunctionClauseError)在...中没有匹配的功能子句

is one of the most frequently happening errors in Elixir, as well as any other language supporting pattern matching in function clauses. 是Elixir以及其他任何支持函数子句中模式匹配的语言中最常见的错误之一。 Consider this contrived example: 考虑这个人为的例子:

defmodule M do
  def test(param) when is_binary(param), do: "binary"
  def test(param) when is_list(param), do: "list"
end
M.test("Hello, world")
#⇒ "binary"
M.test([1, 2, 3])
#⇒ "list"

When there is no function clause, that could be matched against the parameters given, the error above happens: 如果没有可以与给定参数匹配的函数子句,则会发生上述错误:

M.test(42)
#⇒ ** (FunctionClauseError) no function clause matching in M.test/1

That said, the library, you are using, expected other type(s) of one or many parameters. 就是说,您正在使用的库期望使用其他类型的一个或多个参数。 Let's check: :wxFrame.new/4 expects: 让我们检查一下:wxFrame.new/4期望:

Parent = wxWindow:wxWindow()
Id = integer()
Title = unicode:chardata()
Option = {pos, {X::integer(), Y::integer()}} | 
         {size, {W::integer(), H::integer()}} | 
         {style, integer()}

The third parameter is expected to be unicode:chardata() which is in turn Erlang charlist, that is denoted in Elixir by single quotes. 第三个参数应该是unicode:chardata() ,它依次是Erlang字符列表,在Elixir中用单引号表示。 Hence the comment by @Dogbert: use single quotes around ' Game of Life' . 因此,@ Dogbert的评论:在“ Game of Life'周围使用单引号。

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

相关问题 Elixir :( FunctionClauseError)没有函数子句匹配 - Elixir: (FunctionClauseError) no function clause matching 传递地图时出现FunctionClauseError - FunctionClauseError when passing map Elixir-在Mac上设置MIX_ENV会产生FunctionClauseError - Elixir - setting MIX_ENV on a Mac yields FunctionClauseError 为UTC `DateTime`调用`Timex.Timezone.get/2`时`Timex.Timezone.resolve/3`中的`FunctionClauseError`错误 - `FunctionClauseError` error in `Timex.Timezone.resolve/3` when calling `Timex.Timezone.get/2` for a UTC `DateTime` Phoenix 1.3 Elixir jsonapi(FunctionClauseError)在render / 2中没有匹配的函数子句 - Phoenix 1.3 Elixir jsonapi (FunctionClauseError) no function clause matching in render/2 Elixir Pheonix通道(FunctionClauseError)ProjectName.ModuleName.handle_in / 3中没有匹配的功能子句 - Elixir Pheonix Channels (FunctionClauseError) no function clause matching in ProjectName.ModuleName.handle_in/3 Phoenix/Elixir:何时创建新上下文的提示 - Phoenix/Elixir: tips when to create a new Context 将我的erlang库模块myerlib.erl放到elixir树目录中以便从elixir模块调用的位置 - where to place my erlang library module myerlib.erl into elixir tree directory for calling from elixir modules Intellij的新Elixir项目 - New Elixir project in Intellij Elixir - 调用/调用宏 - UndefinedFunctionError - Elixir - Calling / Invoking Macros - UndefinedFunctionError
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM