java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Please post the complete stack trace of the error.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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)
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
DAOImpl
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
1 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
Do you think this is helpful https://stackoverflow.com/questions/45873514/postgresql-hint-you-will-need-to-rewrite-or-cast-the-expression-column-state?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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?
-
2 -
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 |










