• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone,
I am trying to create a user home page for a flight system webapp in eclipse. In the home page I have wallet feature that keeps track of deposits and withdrawals to pay for the flight. I am working on the deposit part. I want the transactions to show up in the user home page where I have a form and also a table for the return data. Those are both setup correctly. I am having trouble setting up the servlet to handle the request and will post my code below. My code is correct as far as running the information as a java application, everything comes back as I want it to. Hopefully, you can help me or at least point me in the right direction. Thanks in advance!

Deposit.java


UserHome.jsp


DepositServlet(thus far). Also the Deposit.jsp have the same code as the return table


And Subject heading is what I keep getting when I run it and I don't know if that's due to parsing the double or what. I don't get it because I don't know what "in" means and I have googled the subject line and either haven't found any explanation or haven't understood the explanation. So help with that would be appreciated also.
 
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given that there's no trim() call anywhere in your posted code, the problem lies elsewhere, or in code called from the posted code.

Please post the complete stack trace of the error.
 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Given that there's no trim() call anywhere in your posted code, the problem lies elsewhere, or in code called from the posted code.

Please post the complete stack trace of the error.



Context Path:/FlyAwayAirlines
Servlet Path:/Deposit
Path Info:null
Query String:password=HelloFresh&deposit=50000
Stack Trace:
java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:556)
at deployment.FlyAwayAirlines.war//flyaway.airlines.servlets.DepositServlet.doGet(DepositServlet.java:31)
at [email protected]//javax.servlet.http.HttpServlet.service(HttpServlet.java:503)
at [email protected]//javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at [email protected]//io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
at [email protected]//io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at [email protected]//io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:68)
at [email protected]//io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.RedirectDirHandler.handleRequest(RedirectDirHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:117)
at [email protected]//io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at [email protected]//io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at [email protected]//io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at [email protected]//io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at [email protected]//io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
at [email protected]//io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
at [email protected]//io.undertow.servlet.handlers.SendErrorPageHandler.handleRequest(SendErrorPageHandler.java:52)
at [email protected]//io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:269)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:133)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:130)
at [email protected]//io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
at [email protected]//io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at [email protected]//org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1530)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:249)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:78)
at [email protected]//io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:99)
at [email protected]//io.undertow.server.Connectors.executeRootHandler(Connectors.java:387)
at [email protected]//io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:841)
at [email protected]//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at [email protected]//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at [email protected]//org.xnio.XnioWorker$WorkerThreadFactory$1$1.run(XnioWorker.java:1280)
at java.base/java.lang.Thread.run(Thread.java:831)
 
Bear Bibeault
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, you need to debug line 31. Most likely, the value of the parameter is null causing the parse to fail.

Use Dev Tools in the browser to look at your request. Is the parameter as expected? Or use logging in the Java code to trace the execution.

Verify that the parameter is null, and then if that's the case, backtrack to find out why.
 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:OK, you need to debug line 31. Most likely, the value of the parameter is null causing the parse to fail.

Use Dev Tools in the browser to look at your request. Is the parameter as expected? Or use logging in the Java code to trace the execution.

Verify that the parameter is null, and then if that's the case, backtrack to find out why.



Thank you, I will see what I can figure out.
 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, this is what I found out with the dev tools. I am also posting my DAO override method to see if I did something wrong there to get an error. One of the dev tools errors said it had to do with the <!DOCTYPE html> but that is included in my <jsp:inlcude page="header"> which is the same way I have it in other working parts of my code. So, if that's an issue than I'm confused why it would be working in the other parts. Any help is appreciated!

DAOImpl


DeveloperTools_Message.png
[Thumbnail for DeveloperTools_Message.png]
 
Marshal
Posts: 28486
113
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right, you have an internal server error. You've already seen that and printed its stack trace, which tells you that your servlet code called Double.getDouble() with a null value. At line 31.



So that means that request.getParameter("initialDeposit") is null. Which, looking at the request you actually passed, it is because you didn't pass any "initialDeposit" parameter with the request.

 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Right, you have an internal server error. You've already seen that and printed its stack trace, which tells you that your servlet code called Double.getDouble() with a null value. At line 31.



So that means that request.getParameter("initialDeposit") is null. Which, looking at the request you actually passed, it is because you didn't pass any "initialDeposit" parameter with the request.


I thought that this line was the request itself because of the "request.getParameter("initialDeposit") at the end of the line.

And how can it be null if the double initialDeposit = 0.0 in the Customers class has been set?
I'm sorry if these are stupid questions, just trying to understand.
 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so I've updated my code and now have a different error. It's reading the initial deposit  parameter now but I'm getting an error that says I need to cast or rewrite the code. So I've looked at what all that means and have tried a few things to correct the error but still no luck. I'm including screenshots of everything so that maybe someone can point me in the right direction. Any help is appreciated and thank you in advance. So one thing I tried is casting this way "String sql = "INSERT INTO wallet VALUES(?,?::numeric,?,?,?) ";". and I have also tried casting in the SQL Shell which is included below.
Console_Error_Message.png
[Thumbnail for Console_Error_Message.png]
SQL_Shell_Code.png
[Thumbnail for SQL_Shell_Code.png]
 
Bartender
Posts: 2466
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe, the type of the column cannot be typed cast.
Do you think this is helpful https://stackoverflow.com/questions/45873514/postgresql-hint-you-will-need-to-rewrite-or-cast-the-expression-column-state?
 
Nathaniel Broome
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Himai Minh wrote:Maybe, the type of the column cannot be typed cast.
Do you think this is helpful https://stackoverflow.com/questions/45873514/postgresql-hint-you-will-need-to-rewrite-or-cast-the-expression-column-state?



Thanks for your response. I actually looked at that example before posting my question. I did go back and rewrite my SQL statement to match but then I get an error saying that "password" in my column is null and I don't understand why. My password is not null and when I run my code as a java application everything is read and displayed correctly. Any ideas? Also if It can't be cast then does that mean I need to go back and fix my code in some other way?
Newest_Error_Message.png
[Thumbnail for Newest_Error_Message.png]
 
Paul Clapham
Marshal
Posts: 28486
113
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nathaniel Broome wrote:I thought that this line was the request itself because of the "request.getParameter("initialDeposit") at the end of the line.

And how can it be null if the double initialDeposit = 0.0 in the Customers class has been set?
I'm sorry if these are stupid questions, just trying to understand.



No. When you write a web app, you write something which can accept HTTP requests from an external client. In Java the web app is typically built from servlets, as in your case.  The client is often a browser but it can be another program, but in either case it sends requests in a specific format to the servlet, which knows how to decipher that format.

So you wrote a servlet which expects the client to send HTTP requests with several parameters, one of which is "initialDeposit". If the servlet doesn't see a parameter with that name then it uses null for the value of the parameter.

Then you sent it a request with only one of the parameters set, so the others (including "initialDeposit") are treated as null.

That's all there is to it. Your Customer class is totally unrelated to this process.

It's not a stupid question, it's just that you skipped over understanding how HTTP is implemented, which leads to confusion.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders
https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing
reply
    Bookmark Topic Watch Topic
  • New Topic