应用程序引擎req.getParameter,类型为float

时间:2012-03-29 07:46:39

标签: java google-app-engine eclipse-plugin floating-point

我正在尝试做一些与App Engine教程(入门)中的留言簿非常相似的内容。但是,我想修改表单中字段的类型。 Eclipse没有显示任何错误,但服务器说:

Problem accessing /. Reason: 

java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()Ljava/lang/Float;

Caused by:
 javax.servlet.ServletException: java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()    Ljava/lang/Float;
 at org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:862)
 at org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:791)
 at org.apache.jsp.prototipo2_jsp._jspService(prototip o2_jsp.java:326)
 at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
 at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
 at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377)
 at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:313)
 at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:260)
 at com.google.appengine.tools.development.PrivilegedJ spServlet.access$101     (PrivilegedJspServlet.java:23)
 at com.google.appengine.tools.development.PrivilegedJ spServlet$2.run(PrivilegedJspServlet.java:59)
 at java.security.AccessController.doPrivileged(Native Method)
 at com.google.appengine.tools.development.PrivilegedJ spServlet.service(PrivilegedJspServlet.java:57)
 at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
 at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:511)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1166)
 at com.google.appengine.tools.development.BackendServ ersFilter.doFilter(BackendServersFilter.java:97)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:388)
 at org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:182)
 at org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:765)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:418)
 at com.google.appengine.tools.development.DevAppEngin eWebAppContext.handle(DevAppEngineWebAppContext.ja va:78)
 at org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:327)
 at org.mortbay.jetty.servlet.Dispatcher.forward(Dispa tcher.java:126)
 at com.google.appengine.tools.development.StaticFileU tils.serveWelcomeFileAsForward(StaticFileUtils.jav a:80)
 at com.google.appengine.tools.development.LocalResour ceFileServlet.maybeServeWelcomeFile(LocalResourceF ileServlet.java:254)
 at com.google.appengine.tools.development.LocalResour ceFileServlet.doGet(LocalResourceFileServlet.java: 120)
 at javax.servlet.http.HttpServlet.service(HttpServlet .java:617)
 at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
 at org.mortbay.jetty.servlet.ServletHolder.handle(Ser vletHolder.java:511)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1166)
 at com.google.appengine.tools.development.HeaderVerif icationFilter.doFilter(HeaderVerificationFilter.ja va:35)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at com.google.appengine.api.blobstore.dev.ServeBlobFi lter.doFilter(ServeBlobFilter.java:60)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at com.google.apphosting.utils.servlet.TransactionCle anupFilter.doFilter(TransactionCleanupFilter.java: 43)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.StaticFileF ilter.doFilter(StaticFileFilter.java:122)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at com.google.appengine.tools.development.BackendServ ersFilter.doFilter(BackendServersFilter.java:97)
 at org.mortbay.jetty.servlet.ServletHandler$CachedCha in.doFilter(ServletHandler.java:1157)
 at org.mortbay.jetty.servlet.ServletHandler.handle(Se rvletHandler.java:388)
 at org.mortbay.jetty.security.SecurityHandler.handle( SecurityHandler.java:216)
 at org.mortbay.jetty.servlet.SessionHandler.handle(Se ssionHandler.java:182)
 at org.mortbay.jetty.handler.ContextHandler.handle(Co ntextHandler.java:765)
 at org.mortbay.jetty.webapp.WebAppContext.handle(WebA ppContext.java:418)
 at com.google.appengine.tools.development.DevAppEngin eWebAppContext.handle(DevAppEngineWebAppContext.ja va:78)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152)
 at com.google.appengine.tools.development.JettyContai nerService$ApiProxyHandler.handle(JettyContainerSe rvice.java:363)
 at org.mortbay.jetty.handler.HandlerWrapper.handle(Ha ndlerWrapper.java:152)
 at org.mortbay.jetty.Server.handle(Server.java:326)
 at org.mortbay.jetty.HttpConnection.handleRequest(Htt pConnection.java:542)
 at org.mortbay.jetty.HttpConnection$RequestHandler.he aderComplete(HttpConnection.java:923)
 at org.mortbay.jetty.HttpParser.parseNext(HttpParser. java:547)
 at org.mortbay.jetty.HttpParser.parseAvailable(HttpPa rser.java:212)
 at org.mortbay.jetty.HttpConnection.handle(HttpConnec tion.java:404)
 at org.mortbay.io.nio.SelectChannelEndPoint.run(Selec tChannelEndPoint.java:409)
 at org.mortbay.thread.QueuedThreadPool$PoolThread.run (QueuedThreadPool.java:582)
 Caused by: java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()Ljava/lang/Float;
 at org.apache.jsp.prototipo2_jsp._jspService(prototip o2_jsp.java:187)
 ... 56 more

我的代码是:

@Persistent
 private Float distance;


public Greeting (User author, String content, Date date, String distance) {
 this.author = author;
 this.content = content;
 this.date = date;
 this.distance = Float.parseFloat(distance); } 

}

public Float getDistance() {

return distance;
 }

Eclipse说运行应用程序时一切正常,但是当我在localhost域中打开文件时,我看到了之前写过的错误。

但是,如果我改变这样的代码:

@Persistent
 private String distance;


public Greeting (User author, String content, Date date, String distance) {
 this.author = author;
 this.content = content;
 this.date = date;
 this.distance = distance;


}

public String getDistance() {

return distance;
 }

谢谢!

2 个答案:

答案 0 :(得分:1)

我认为你有两个问题:

  1. 某处你有一个Long字段,其中data是一个字符串,无法转换为long。

  2. 为什么要将distance参数转换为Integer,然后将其分配给float字段?请改用Float.parseFloat(..)

答案 1 :(得分:0)

您收到的错误是从数据存储区读回已经保留的实体的时间。看起来您已经存储了具有String属性的数据,您现在正在尝试读入已将该属性重新定义为Long的实体 - 您是否更改了ID字段的类型?