DonJayamanne / javaVSCode

Extension for java development on VSCode (deprecated)
https://marketplace.visualstudio.com/items?itemName=donjayamanne.javaDebugger
MIT License
43 stars 30 forks source link

How can i use scanner in vscode ? #67

Open Estebjor opened 6 years ago

Estebjor commented 6 years ago

I want to use a number from the keyboard, how can i configure VSCODE. ? ` import java.util.Scanner;

class Acceptinput{

public static void main (String[] args){
    int a;
    Scanner s = new Scanner (System.in);
    System.out.println("Enter your lucky number");
    a = s.nextInt();
    System.out.println("Your lucky number is: " +a);
}

} `

faustinoaq commented 6 years ago

use "externalConsole": true in your launch.json

On Fri, Aug 25, 2017 at 1:40 AM, Estebjor notifications@github.com wrote:

I want to use a number from the keyboard, how can i configure VSCODE. ? ` import java.util.Scanner;

class Acceptinput{

public static void main (String[] args){ int a; Scanner s = new Scanner (System.in); System.out.println("Enter your lucky number"); a = s.nextInt(); System.out.println("Your lucky number is: " +a); }

} `

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7NxwRO-n0QhADxA_tO0fdUpbXD434Pks5sbmxXgaJpZM4PCR8b .

Estebjor commented 6 years ago

Actually it is true `{ "version": "0.2.0", "configurations": [

    {
        "name": "Java",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}/bin",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ]
    },
    {
        "name": "Java Console App",
        "type": "java",
        "request": "launch",
        "stopOnEntry": true,
        "jdkPath": "${env:JAVA_HOME}/bin",
        "cwd": "${fileDirname}",
        "startupClass": "${fileBasenameNoExtension}",
        "classpath": [
            ".",
            "${fileDirname}"
        ],
        "externalConsole": true
    }
]

}`

faustinoaq commented 6 years ago

Then, be sure that "Java Console App" is checked in debug menu before click the green play button. :-)

On Fri, Aug 25, 2017 at 10:01 AM, Estebjor notifications@github.com wrote:

Actually it is true `{ "version": "0.2.0", "configurations": [

{
    "name": "Java",
    "type": "java",
    "request": "launch",
    "stopOnEntry": true,
    "jdkPath": "${env:JAVA_HOME}/bin",
    "cwd": "${fileDirname}",
    "startupClass": "${fileBasenameNoExtension}",
    "classpath": [
        ".",
        "${fileDirname}"
    ]
},
{
    "name": "Java Console App",
    "type": "java",
    "request": "launch",
    "stopOnEntry": true,
    "jdkPath": "${env:JAVA_HOME}/bin",
    "cwd": "${fileDirname}",
    "startupClass": "${fileBasenameNoExtension}",
    "classpath": [
        ".",
        "${fileDirname}"
    ],
    "externalConsole": true
}

]

}`

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67#issuecomment-324946774, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7Nx0y7IhjBPkkEjcJKrcSev9eJaPuvks5sbuHigaJpZM4PCR8b .

Estebjor commented 6 years ago

It shows me: Failed to start the program, Timeout after 5000 milli-seconds

faustinoaq commented 6 years ago

Ok, I need more information about your environment, What is your Operative System?

On Fri, Aug 25, 2017 at 1:29 PM, Estebjor notifications@github.com wrote:

It show me: Failed to start the program, Timeout after 5000 milli-seconds

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DonJayamanne/javaVSCode/issues/67#issuecomment-325002700, or mute the thread https://github.com/notifications/unsubscribe-auth/AC7Nx8F9-WAjhyQY1AQmt16Pw4jEh2euks5sbxKlgaJpZM4PCR8b .

Estebjor commented 6 years ago

I'm using win10.

faustinoaq commented 6 years ago

Seems you have some different configuration in your machine.

I also have Windows 10, and this extension works well: (I used your code as example)

issue67

GorvGoyl commented 6 years ago

it is a bug that we can't use internal terminal for user input while in debug mode. for Python/C# internal terminal is working fine while debugging. I guess the issue is more on the VS code side but not sure.

faustinoaq commented 6 years ago

This was the original issue :sweat_smile:

weinand commented 6 years ago

I don't think that this is a VS Code issue.

The only question is: does the Java debugger support to communicate over a separate communication channel so that stdin/stdout if freely available to the Java program. If the debugger itself uses stdin/stdout to communicate with the user, the Java program cannot read from stdin at the same time.

faustinoaq commented 6 years ago

I was a bit confused, My bad :sweat_smile:

faustinoaq commented 6 years ago

@weinand Thanks for keep discussion here :+1:

faustinoaq commented 6 years ago

I added this issue to Known issues in README for now.

Also I added a tiny Contributing guide if someone want to help to fix this.