Page 1 of 2 12 LastLast
Results 1 to 20 of 21
  1. #1
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default app engine req.getParameter with type float

    Hi,





    I'm trying to do something very similar to the Guestbook which is in the App Engine tutorial (get started). However, I want to modified the types of the fields in the form. Eclipse doesn't show any error, but the server says:

    HTTP ERROR 500 Problem accessing /. Reason:
    java.lang.String cannot be cast to java.lang.Long

    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at org.datanucleus.store.appengine.TypeConversionUtil s$1.apply(TypeConversionUtils.java:47) at org.datanucleus.store.appengine.TypeConversionUtil s$1.apply(TypeConversionUtils.java:45) at org.datanucleus.store.appengine.TypeConversionUtil s.datastoreValueToPojoValue(TypeConversionUtils.ja va:317) at org.datanucleus.store.appengine.DatastoreFieldMana ger.fetchObjectField

    This is what I'm doing:

    Java Code:
    @Persistent 
    private float weight; 
    public Greeting (User author, String content, Date date, String weight) { this.author = author; 
    this.content = content; 
    this.date = date; 
    this.weight = Float.parseFloat(weight); } 
    public float getWeight() { 
    return weight; }
    I don't know where the error is...

    Thank you in advance!!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    What is App Engine?

    And does your code really look like that with no whitespace or formatting?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    App Engine is a plugin for Eclipse to develop web aplications. Yes, my code has whitespaces, etc. I'm sorry, I've just copied and pasted it. I can copy-paste again if it is a mess! ;) Also, my code is inside a class called Greeting, almost equal to an example in the Get Started tutorial you can find in the App Engine of Google.The difference is that I'm trying to work with a field which is a float instead a string :)
    Last edited by Natilla; 04-03-2012 at 06:38 PM.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    Is there some mapping file somewhere for your persistent object?
    Is there anything else in the stack trace that you might be able to trace to your code?


    Because that trace as it stands is simply telling you that something isn't mapping correctly when, I think, it's trying to read some data.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    This object is read in another class as a string:

    String distance = req.getParameter("weight");
    Greeting greeting = new Greeting(user, content, date, weight);


    I do that, because the method getParameter only has string parameters. So I try to convert the string in float in the Greeting class. That means there are only two classes where the object appears.

  6. #6
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Well, in fact, in my .jsp file, I read from a form the field and it is showed in a table:

    <TD id="weight"><%= g.getWeight() %></TD>

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    But that's all your code, and the error looks to be coming from within App Engine.
    What is the full stack trace?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    No this is not all the code, but the other objects are string. I'm sorry because I've forgotten to say my object it is no "weight" anymore. Now it is called "distance". if I change "distance" to string everything is ok. This is the entire stack trace:


    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

    Caused by:
    java.lang.NoSuchMethodError: prototipo2.Greeting.getDistance()Ljava/lang/Float;
    at org.apache.jsp.prototipo2_jsp._jspService(prototip o2_jsp.java:187)
    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)

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    Which is completely different to the error in your original post, which was a ClassCastException.
    You need to give us the correct information if you want someone to be able to help.

    For this exception, your JSP page 'prototipo2' is (somewhere) trying to call a getDistance() method on your Greeting class, which does not exist.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Yeah, I'm sorry for the mess. Now, my GetWeight method doesn't exist anymore. Instead, I've writen the getDistance() method. All the code is the same but with this change, so:

    @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;
    }

    And Eclipse says everything is ok when I run the app, but when I open the file in my localhost domain, I see the error that I wrote you before.

    However, if I change the code in something like this:

    @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;
    }

    EVERYTHING is ok!

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    And do you have the full stack trace for that exception?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  12. #12
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Do you mean the post I've written at 6:02 PM? Is there any other trace?

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    In your original post you had:
    HTTP ERROR 500 Problem accessing /. Reason:
    java.lang.String cannot be cast to java.lang.Long

    Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long at org.datanucleus.store.appengine.TypeConversionUtil s$1.apply(TypeConversionUtils.java:47) at org.datanucleus.store.appengine.TypeConversionUtil s$1.apply(TypeConversionUtils.java:45) at org.datanucleus.store.appengine.TypeConversionUtil s.datastoreValueToPojoValue(TypeConversionUtils.ja va:317) at org.datanucleus.store.appengine.DatastoreFieldMana ger.fetchObjectField
    That is not going to be the full stack trace.
    If that is not the exception you are now getting then what is it?
    (And please use post numbers, as we are in different timezones)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Ok, excuse me! I refer to my 8 message; this is the full stack trace and the "correct" version. I mean, the code that I want to do produces this trace.
    Thanks!

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    Right.
    In which case can you show the code in the JSP where getDistance() is called?
    Any code on that page where it is called or that field is referenced?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  16. #16
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Yes:

    <TR id="distance" >
    <TD >Distancia</TD>
    <TD id="distance1"><%= g.getDistance() %></TD>
    </TR>
    <TR>
    </TR>

    And I read from the datastore by using:

    String query = "select from " + Greeting.class.getName() + " order by date desc range 0,1";

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    Where is g declared?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Here:
    if (greetings.isEmpty()) {
    %>
    <p>The guestbook has no messages.</p>
    <%
    } else {
    for (Greeting g : greetings) {
    if (g.getAuthor() == null) {
    %>
    <p> An anonymous person wrote:</p>
    <%
    }else{
    %>
    <p><b><%= g.getAuthor().getNickname() %> </b> wrote:</p>
    <%
    }
    %>

  19. #19
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: app engine req.getParameter with type float

    I can only assume that there is a mismatch somewhere.
    The error implies it is looking for the getDistance which returns a Float, but isn't finding it.
    That says to me that the new class hand't deployed for whatever reason.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  20. #20
    Natilla is offline Member
    Join Date
    Apr 2012
    Posts
    11
    Rep Power
    0

    Default Re: app engine req.getParameter with type float

    Yes, all I know is the getParameter method only accepts strings as parameters. I want to define the fields in the datastore with their types (string, date, content, float...), define the fields in the form inside the .jsp file as strings, read from the form as strings, convert them to their right types and write them in the datastore. So this is what I'm trying to do...

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: 10-22-2011, 06:50 AM
  2. dynamically generation of request.getParameter()
    By ras_pari in forum New To Java
    Replies: 12
    Last Post: 05-21-2010, 12:12 PM
  3. Java, MySQL and Data Type Float
    By digidigdj in forum AWT / Swing
    Replies: 0
    Last Post: 03-11-2010, 08:42 PM
  4. Replies: 2
    Last Post: 11-16-2007, 02:24 PM
  5. Help with request.getParameter()
    By Albert in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-13-2007, 04:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •