Noir render函数导致NullPointerException [英] Noir render function causes NullPointerException

查看:224
本文介绍了Noir render函数导致NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Clojure应用程序中,我使用Noir作为web框架。
我有一个定义的post页面,将一些数据保存到mongodb数据库,然后尝试呈现另一个页面:

 (defpage/ delivery / save[delivery] 
(let [id(save-delivery delivery)]
(render/ delivery / listid))

我有另一个页面:

 (defpage/ delivery / list /:id{:id id} 
(应该渲染页面))

但是我在调​​用render函数时得到一个NullPointerException
任何想法为什么会发生这种情况
如果你需要更多的细节,请让我知道。 / p>

感谢,
Nico



这里是stacktrace:

  java.lang.NullPointerException 
at noir.core $ render.doInvoke(core.clj:161)
at clojure.lang.RestFn.invoke (restFn.java:423)
at mailjure.views.delivery $ POST__delivery__save.invoke(delivery.clj:115)
at mailjure.views.delivery $ eval477 $ fn__478.invoke(delivery.clj:109 )
at compojure.core $ if_route $ fn__271.invoke(core.clj:39)
at compojure.core $ if_method $ fn__264.invoke(core.clj:24)
at compojure。核心$ routing $ fn__286.invoke(core.clj:98)
at clojure.core $ some.invoke(core.clj:2390)
at compojure.core $ routing.doInvoke(core.clj: 98)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core $ apply.invoke(core.clj:603)
at compojure.core $ routes $ fn__290.invoke(core.clj:103)
at noir.server.handler $ init_routes $ fn__1422.invoke(handler.clj:92)
at noir.request $ wrap_request_map $ fn__1324.invoke .clj:14)
at hiccup.middleware $ wrap_base_url $ fn__860.invoke(middleware.clj:12)
at noir.session $ noir_flash $ fn__1347.invoke(session.clj:92)
在ring.middleware.flash $ wrap_flash $ fn__642.invoke(flash.clj:14)
at noir.session $ noir_session $ fn__1337.invoke(session.clj:56)
在ring.middleware。 session $ wrap_session $ fn__635.invoke(session.clj:40)
at ring.middleware.cookies $ wrap_cookies $ fn__572.invoke(cookies.clj:150)
at noir.cookies $ noir_cookies $ fn__1188。 invoke(cookies.clj:66)
at ring.middleware.cookies $ wrap_cookies $ fn__572.invoke(cookies.clj:150)
at noir.validation $ wrap_noir_validation $ fn__1375.invoke(validation.clj: 90)
at noir.statuses $ wrap_status_pages $ fn__1286.invoke(statuses.clj:34)
at ring.middleware.reload $ wrap_reload $ fn__712.invoke(reload.clj:18)
at noir.exception $ wrap_exceptions $ fn__1317.invoke(exception.clj:57)
at noir.options $ wrap_options $ fn__1277.invoke(options.clj:34)
at compojure.core $ routing $ fn__286 .invoke(core.clj:98)
at clojure.core $ some.invoke(core.clj:2390)
at compojure.core $ routing.doInvoke(core.clj:98)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core $ apply.invoke(core.clj:603)
at compojure.core $ routes $ fn__290.invoke core.clj:103)
at ring.middleware.keyword_params $ wrap_keyword_params $ fn__445.invoke(keyword_params.clj:27)
at ring.middleware.nested_pa​​rams $ wrap_nested_pa​​rams $ fn__482.invoke(nested_pa​​rams.clj: 65)
at ring.middleware.params $ wrap_params $ fn__390.invoke(params.clj:76)
at ring.middleware.multipart_params $ wrap_multipart_params $ fn__417.invoke(multipart_params.clj:103)
at ring.adapter.jetty $ proxy_handler $ fn__377.invoke(jetty.clj:16)
在ring.adapter.jetty.proxy $ org.mortbay.jetty.handler.AbstractHandler $ 0.handle(未知来源)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org .mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection $ RequestHandler.content(HttpConnection.java:943)
at org.mortbay.jetty.HttpParser .parseNext(HttpParser.java:756)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404 )
at org.mortbay.jetty.bio.SocketConnector $ Connection.run(SocketConnector.java:228)
at org.mortbay.thread.QueuedThreadPool $ PoolThread.run(QueuedThreadPool.java:582)


解决方案

您需要指定完全相同的网址:

 (defpage/ delivery / list /:id{id:id} 
whoot!)

(defpage/ delivery / save[]
(let [id 100]
(render/ delivery / list /:idid)))

但这是丑陋的,最好给你的页面命名:

 (defpage delivery-page/ delivery / list /:id{id:id} 
whoot!)

/ delivery / save[]
(let [id 100]
(render delivery-page id)))

这很漂亮。此外,它还具有以下优势:您可以轻松测试交付页面:

 (第123页交货)


In my Clojure application I'm using Noir as web framework. I have one post page defined which is saving some data onto a mongodb database and I'm then trying to render another page:

(defpage "/delivery/save" [delivery]
 (let [id (save-delivery delivery)]
    (render "/delivery/list" id))

I then have another page:

(defpage "/delivery/list/:id" {:id id}
   (this should render the page))

However I'm getting a NullPointerException when calling the render function. Any idea why is this happening? Please let me know if you need more details.

Thanks, Nico

Here's the stacktrace:

java.lang.NullPointerException
    at noir.core$render.doInvoke(core.clj:161)
    at clojure.lang.RestFn.invoke(RestFn.java:423)
    at mailjure.views.delivery$POST__delivery__save.invoke(delivery.clj:115)
    at mailjure.views.delivery$eval477$fn__478.invoke(delivery.clj:109)
    at compojure.core$if_route$fn__271.invoke(core.clj:39)
    at compojure.core$if_method$fn__264.invoke(core.clj:24)
    at compojure.core$routing$fn__286.invoke(core.clj:98)
    at clojure.core$some.invoke(core.clj:2390)
    at compojure.core$routing.doInvoke(core.clj:98)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invoke(core.clj:603)
    at compojure.core$routes$fn__290.invoke(core.clj:103)
    at noir.server.handler$init_routes$fn__1422.invoke(handler.clj:92)
    at noir.request$wrap_request_map$fn__1324.invoke(request.clj:14)
    at hiccup.middleware$wrap_base_url$fn__860.invoke(middleware.clj:12)
    at noir.session$noir_flash$fn__1347.invoke(session.clj:92)
    at ring.middleware.flash$wrap_flash$fn__642.invoke(flash.clj:14)
    at noir.session$noir_session$fn__1337.invoke(session.clj:56)
    at ring.middleware.session$wrap_session$fn__635.invoke(session.clj:40)
    at ring.middleware.cookies$wrap_cookies$fn__572.invoke(cookies.clj:150)
    at noir.cookies$noir_cookies$fn__1188.invoke(cookies.clj:66)
    at ring.middleware.cookies$wrap_cookies$fn__572.invoke(cookies.clj:150)
    at noir.validation$wrap_noir_validation$fn__1375.invoke(validation.clj:90)
    at noir.statuses$wrap_status_pages$fn__1286.invoke(statuses.clj:34)
    at ring.middleware.reload$wrap_reload$fn__712.invoke(reload.clj:18)
    at noir.exception$wrap_exceptions$fn__1317.invoke(exception.clj:57)
    at noir.options$wrap_options$fn__1277.invoke(options.clj:34)
    at compojure.core$routing$fn__286.invoke(core.clj:98)
    at clojure.core$some.invoke(core.clj:2390)
    at compojure.core$routing.doInvoke(core.clj:98)
    at clojure.lang.RestFn.applyTo(RestFn.java:139)
    at clojure.core$apply.invoke(core.clj:603)
    at compojure.core$routes$fn__290.invoke(core.clj:103)
    at ring.middleware.keyword_params$wrap_keyword_params$fn__445.invoke(keyword_params.clj:27)
    at ring.middleware.nested_params$wrap_nested_params$fn__482.invoke(nested_params.clj:65)
    at ring.middleware.params$wrap_params$fn__390.invoke(params.clj:76)
    at ring.middleware.multipart_params$wrap_multipart_params$fn__417.invoke(multipart_params.clj:103)
    at ring.adapter.jetty$proxy_handler$fn__377.invoke(jetty.clj:16)
    at ring.adapter.jetty.proxy$org.mortbay.jetty.handler.AbstractHandler$0.handle(Unknown Source)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:943)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.jetty.bio.SocketConnector$Connection.run(SocketConnector.java:228)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

解决方案

You need to specify exactly the same url:

 (defpage "/delivery/list/:id" {id :id}
   "whoot!")

 (defpage "/delivery/save" []
   (let [id 100]
     (render "/delivery/list/:id" id)))

But this is ugly, it is better to give names to your pages:

 (defpage delivery-page "/delivery/list/:id" {id :id}
   "whoot!")

 (defpage "/delivery/save" []
   (let [id 100]
     (render delivery-page id)))

Which is pretty neat. Also it has the advantage that you can easily test your delivery-page:

 (delivery-page 123)

这篇关于Noir render函数导致NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆