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

Java

500 Internal Error - Again

I've been following the video of Craig Dennis about Spark, and I've reached the part where we make out 'index.hbs' file and then alter our java code to call the file. however when I run it I get 500 internal error on the localhost and then I get this as one of the errors

One of the errors I get in the IntelliJ terminal is ''' [qtp645337405-21] INFO spark.http.matching.MatcherFilter - The requested route [/index] has not been mapped in Spark for Accept: [text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8] '''

public class Main {
    public static void main(String[] args) {

        //Map map = new HashMap();
        //map.put("name", "Imtanan");
       // get("/", (rq, rs) -> new ModelAndView(map, "index.hbs"), new HandlebarsTemplateEngine());

        get("/", (req, res) -> {
            return new ModelAndView(null, "index.hbs");
        }, new HandlebarsTemplateEngine());
    }
}
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello Students</title>
</head>
<body>
<h1>Welcome Students!</h1>
</body>
</html>

2 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Cool, move your index.hbs file into a new folder resources/templates/index.hbs.

Weird error, but looks like you missed creating that templates folder.

Hope this works!

Thank you sooooooooooooooooooooo much you are the man Craig Dennis now I can continue :D

Craig Dennis
Craig Dennis
Treehouse Teacher

Woohoo! Thanks for bringing it up! That was a weird error for sure, glad it's here for others that might run into the same problem!

Keep at it!

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Hmmm... are you going to http://localhost:4567/ or someplace else? Looks like you might be requesting the /index page, which you haven't mapped, you just mapped the /

I'm going exactly to that link Craig Dennis and it still shows the same error, despite me having rerun the server

Craig Dennis
Craig Dennis
Treehouse Teacher

I'm not sure it would matter, but can you tell me where the index.hbs file lives?

Craig Dennis
Craig Dennis
Treehouse Teacher

Also can you share your imports please? Only other thing I can think of ;)

yeah sure, my 'index.hbs' file resides C:\Users\Mani\IdeaProjects\course-ideas\src\main\resources\index.hbs and that is the direct path.

the imports are ::::

package com.teamtreehouse.courses;

import spark.ModelAndView; import spark.template.handlebars.HandlebarsTemplateEngine;

import static spark.Spark.get;

also I thought I'd add the dependencies as I had to add an extra to what the video showed as mine is a later version

compile 'com.sparkjava:spark-core:2.5.2'

compile 'com.sparkjava:spark-template-handlebars:2.3'

compile 'org.slf4j:slf4j-simple:1.7.21'

testCompile group: 'junit', name: 'junit', version: '4.11'

Thanks Craig Dennis :)