开发者

Eclipse IDE doesnt allow me to give the input while running groovy script

I tried to run the groovy script. But unfortunately the script does not ask me for the input and through null pointer exceptions. Please help me what I need to do for this.

static startShell() {

    client = new Client()

    // TODO add Windows compatibility check
    def historyFile = new File(System.getProperty("user.home"), "kitty.history")
    historyFile.createNewFile()

    def history = new History(historyFile)
    def reader = new ConsoleReader()

    reader.setBellEnabled(false)
    reader.setUseHistory(true)
    rea开发者_JS百科der.setDefaultPrompt(PROMPT)
    reader.setHistory(history)
    reader.addCompletor(new SimpleCompletor(commands as String[]))

    LOOP: while (true) {
        def input = reader?.readLine().trim()

        if (input.length() == 0)
            continue

        if (["exit", "quit"].contains(input.tokenize().get(0)))
            break LOOP

        try {
            inputHandler(input)
        }
        catch (Exception e) {
            println e.getMessage()
        }

I also tried by replacing the reader? with reader also.

Error:

kitty> Caught: java.lang.NullPointerException: Cannot invoke method trim() on null object
at org.apache.kitty.CmdShell.startShell(CmdShell.groovy:100)
at org.apache.kitty.CmdShell.main(CmdShell.groovy:79)

Please Help


I believe this is related to this question:

java.io.Console support in Eclipse IDE

Essentially, Eclipse does not support Console Reader for running applications - though I'm confused as to how Andrew Eisenberg got a working result in Eclipse if that is the case.


Can you simplify your program into something that I can run? I tried something very simple and I was able to have it run both on the command line and inside Eclipse.

Here's the script I created:

import jline.ConsoleReader

def reader = new ConsoleReader() LOOP: while (true) { def input = reader?.readLine().trim()

    if (input.length() == 0)
        continue

    if (["exit", "quit"].contains(input.tokenize().get(0)))
        break LOOP

    println "You said: " + input
}

Can you try running this and see if this works for you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜