Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error: Route() in Route cannot be applied to String

I'm designing a Java based MongoDB app and I've ran into a snag when working with Spark.

package com.tengen;

import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;

public class HelloWorldSparkStyle {
    public static void main(String[] args) {
        Spark.get(new Route("/") {
            @Override
            public Object handle(Request request, Response response) {
                return "Hello World From Spark";
            }
        });
    }
}

On new Route("/") I get the error Route() in route cannot be applied to java.lang.string.

I'm confused as to why this doesn't work as I've followed their code exactly. enter image description here

like image 348
Paul Alexander Burkart Avatar asked May 27 '14 20:05

Paul Alexander Burkart


1 Answers

This should probably be posted on the MongoDB class forum, but I ran into a similar issue. Looks like the get method changed from when the course material was produced. The get now requires a path and a Route

get(path, Route)

import spark.Request;
import spark.Response;
import spark.Route;
import spark.Spark;

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

        Spark.get("/", new Route() {
                public Object handle(final Request request, final Response response){
                return "Hello World from Spark";
            }
        });
    }
}
like image 132
Mike Avatar answered Sep 20 '22 15:09

Mike