Why the error? [code] output: ''' rbw-prompt.core> (-main) Database already unlocked.…
- User
Why the error?
(ns rbw-prompt.core (:require [clojure.java.shell :as shell] [clojure.string :as str] [cljfx.api :as fx] [cljfx.fx.text-field :as text-field] [cljfx.fx.list-view :as list-view]) (:gen-class)) (defn fuzzy-match [query accounts] (let [lower-query (str/lower-case query)] (filter #(str/includes? (str/lower-case %) lower-query) accounts))) (defn main-view [state] (let [{:keys [accounts input suggestions]} state] {:fx/type :v-box :spacing 10 :children [{:fx-type :text-field :text input :on-text-changed (fn [new-text] (swap! state assoc :input new-text :suggestions (fuzzy-match new-text accounts)))} {:fx-type :list-view :items suggestions :on-mouse-clicked (fn [event] (when (= (.getClickCount event) 2) (let [selected-item (.getSelectedItem event)] (when selected-item (println "Selected:" selected-item)))))}]})) (defn -main [& args] (def unlocked true) ;; Prelim checks for locked database. (if (not (= (:out (shell/sh "rbw" "unlocked")) "")) (let [res (shell/sh "rbw" "unlock")] (when (= (:exit res) 1) (println "Failed to unlock rbw.") (def unlocked false))) (println "Database already unlocked. Proceeding.")) ;; Prompting (let [accounts (-> (:out (shell/sh "rbw" "list")) str/split-lines)] ;; Init app state (def renderer (fx/create-renderer)) (let [state (atom {:accounts accounts :input "" :suggestions []})] (renderer {:fx/type :stage :showing true :title "rbw-prompt" :scene {:fx/type :scene :root (main-view state) :width 400 :height 300}}))))output: ''' rbw-prompt.core> (-main) Database already unlocked. Proceeding. #<Promise@5e799b21: :not-delivered>java.lang.IllegalArgumentException: No implementation of method: :create of protocol: #'cljfx.lifecycle/Lifecycle found for class: nil at clojure.core_cache_protocol_fn.invoke(core_deftype.clj:576) at cljfx.lifecyclefn__15196create_dynamic_component.invokeStatic(lifecycle.clj:36) at cljfx.lifecyclereify__15247.create(lifecycle.clj:43) at cljfx.lifecyclefn__15380.invoke(lifecycle.clj:369) at cljfx.lifecyclefn__15196wrap_manyfn__15340update.invokeStatic(core.clj:6231) at clojure.corewrap_manyfn__15340.invoke(lifecycle.clj:300) at clojure.lang.PersistentVector.reduce(PersistentVector.java:343) at clojure.corereduce.invoke(core.clj:6868) at cljfx.lifecyclefn__15336.invoke(lifecycle.clj:299) at cljfx.lifecyclefn__15196create_props$fn__15972.invoke(composite.clj:22) at clojure.lang.PersistentArrayMap.kvreduce(PersistentArrayMap.java:429) '''
- Assistant
The error occurs because you used
:fx-typeinstead of:fx/typein your UI component maps within themain-viewfunction. In cljfx, the correct key for specifying the type of a component is:fx/type(with a slash), not:fx-type.Here's the problematic part of your code:
{:fx-type :text-field :text input ...}It should be:
{:fx/type :text-field :text input ...}Similarly, update all occurrences of
:fx-typeto:fx/typein yourmain-viewfunction. The incorrect key causes the cljfx renderer to receive for the component type, leading to the error: