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 Intro to Java Web Development with Spark Diving into Web Development Sending Responses

I am getting an error when I try to run this code, it says ERROR spark.Spark - ignite failed

When I try to run my code this is what I get this at the end

[Thread-1] ERROR spark.Spark - ignite failed
java.net.BindException: Address already in use: bind
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:433)
    at sun.nio.ch.Net.bind(Net.java:425)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:298)
    at org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80)
    at org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at org.eclipse.jetty.server.Server.doStart(Server.java:431)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
    at spark.embeddedserver.jetty.EmbeddedJettyServer.ignite(EmbeddedJettyServer.java:130)
    at spark.Service.lambda$init$2(Service.java:504)
    at java.lang.Thread.run(Thread.java:748)

Process finished with exit code 100

Java Code:

package com.teamtreehouse.courses;

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

import static spark.Spark.get;

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

        get ("/", (req, res) -> {
              return new ModelAndView(null, "index.hbs");
        }, new HandlebarsTemplateEngine());
    }
}

index.hbs code:

<!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>

Fahad Mutair I have updates the question with some code.

2 Answers

Luca Cunico
PLUS
Luca Cunico
Courses Plus Student 14,196 Points

Hello, The error you got is because you have another server running. Close all run tasks and try again.

You can see this by reading this line:

java.net.BindException: Address already in use: bind
Naval Kulkarni
Naval Kulkarni
13,782 Points

Follow this stackoverflow thread and your problem will be solved. i was getting the same error. Some java.exe process wass listening on port 4567, once i ended it, the error was gone.

Here is the link:

https://stackoverflow.com/a/12737775