Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Patrick Bluth
13,285 Points500 Internal Error - NotFoundException
Hi everyone I'm working on the Intro to Java Web Development With Spark course, and I've hit a little roadblock. Specifically on the "details" video.
I have everything running for the voting system until I actually need to vote. The page redirects to the slug link (ex voting for example goes to http://localhost:4567/ideas/%20example/votehttp://localhost:4567/ideas/%20example/vote) and I get the error. Not sure why it's not redirecting to the /ideas page again
[Thread-0] INFO org.eclipse.jetty.util.log - Logging initialized @381ms
[Thread-0] INFO spark.webserver.JettySparkServer - == Spark has ignited ...
[Thread-0] INFO spark.webserver.JettySparkServer - >> Listening on 0.0.0.0:4567
[Thread-0] INFO org.eclipse.jetty.server.Server - jetty-9.3.2.v20150730
[Thread-0] INFO org.eclipse.jetty.server.ServerConnector - Started ServerConnector@186b9aa{HTTP/1.1,[http/1.1]}{0.0.0.0:4567}
[Thread-0] INFO org.eclipse.jetty.server.Server - Started @614ms
[qtp13384719-18] ERROR spark.webserver.MatcherFilter -
com.teamtreehouse.courses.model.NotFoundException
at com.teamtreehouse.courses.model.SimpleCourseIdeaDAO$$Lambda$14/21507372.get(Unknown Source)
at java.util.Optional.orElseThrow(Optional.java:290)
at com.teamtreehouse.courses.model.SimpleCourseIdeaDAO.findBySlug(SimpleCourseIdeaDAO.java:30)
at com.teamtreehouse.courses.Main.lambda$main$7(Main.java:68)
at com.teamtreehouse.courses.Main$$Lambda$8/12609085.handle(Unknown Source)
at spark.RouteImpl$1.handle(RouteImpl.java:58)
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:162)
at spark.webserver.JettyHandler.doHandle(JettyHandler.java:61)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:302)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
Snippet from main class
post("/ideas/:slug/vote", (req, res) -> {
CourseIdea idea = dao.findBySlug(req.params("slug"));
idea.addVoter(req.attribute("username"));
res.redirect("/");
return null;
});
}
Slug from SimpleCourseIdeaDAO
@Override
public CourseIdea findBySlug(String slug) {
return ideas.stream()
.filter(idea -> idea.getSlug().equals(slug))
.findFirst()
.orElseThrow(NotFoundException::new);
}
}
NotFoundException Class
public class NotFoundException extends RuntimeException{
}
ideas.hbl file
<ul>
{{#each ideas}}
<li>
<form action="/ideas/ {{ slug }}/vote" method="post">
{{ title }}( {{ voteCount }} votes) <button>Vote</button>
</form>
</li>
{{/each}}
</ul>
I think that's all I need...
1 Answer
David Remington
18,326 PointsCan you please try removing the space between the '/' character and the {{ slug }} in your ideas.hbl file like so:
<form action="/ideas/{{ idea.slug }}/vote" method="post">
<button>Vote</button>
</form>
The '%20' you are seeing in your path is the url encoded character for a space and I have a suspicion that might be causing the Main class to not recognize what route you are actually on.
Patrick Bluth
13,285 PointsPatrick Bluth
13,285 PointsAwesome David! Thank you so much! Its working fine now. I spent hours looking for that little error. I really appreciate your help!