Issue
I am using Netbeans 11.2 w/ Java 10.0.1+9 and have created a JavaApp.
package hellowant;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int number1;
int number2;
int sum;
String str;
Scanner input = new Scanner(System.in);
System.out.print ("Enter first integer: ");
str = input.nextLine ();
number1 = Integer.parseInt(str);
System.out.print ("Enter second integer:");
str =input.nextLine ();
number2 = Integer.parseInt(str);
sum = number1 + number2;
System.out.printf ( "Sum is %d\n", sum);
}
}
When I create the project using Ant and run it in the Netbeans debugger it works fine. However I have also attempted to run the project as Maven and Gradle project and in both instances the program fails in its attempt to get `Input.nextline(). I have found the debug message: Attaching to localhost:5005 Connection refused. I have not been able to identify the settings within either Maven or Gradle that will correct this problem.
Solution
Usually when you get a connection refused exception on any port it means that you are already using the port elsewhere (or you don’t have permission to bind to it at all which is less likely here).
Are you sure you don’t have the ant copy or a duplicate copy of maven or gradle ones already running? I’d close the IDE and make sure task manager/etc report no java apps then try again.
Answered By - John Humphreys