簡體   English   中英

從Elixir調用:wxFrame.new時發生FunctionClauseError

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

我只有兩個問題:)

  1. 怎么了?
  2. 我如何不問Stackoverflow而了解出了什么問題?

葯劑代碼:

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

輸出:

** (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模塊: https : //github.com/ElixirWin/wxElixir

Dogbert已經回答了第一個問題,我會回答第二個問題。

**(FunctionClauseError)在...中沒有匹配的功能子句

是Elixir以及其他任何支持函數子句中模式匹配的語言中最常見的錯誤之一。 考慮這個人為的例子:

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"

如果沒有可以與給定參數匹配的函數子句,則會發生上述錯誤:

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

就是說,您正在使用的庫期望使用其他類型的一個或多個參數。 讓我們檢查一下:wxFrame.new/4期望:

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

第三個參數應該是unicode:chardata() ,它依次是Erlang字符列表,在Elixir中用單引號表示。 因此,@ Dogbert的評論:在“ Game of Life'周圍使用單引號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM