Recently I face a strange problem in java program. I need to take user input and need to do some calculation on it. However when I am running a program with user input using Scanner class, I got same error message. I have tried using NetBeans 12.0 with Gradle and other online java compiler to see the problem. But in both cases I got the same exception error message. As in every program with user input with Scanner class, I got the same error message, hence, as a reference I am giving a sample program below, which also gives the same error message.
package RevisedMixedAlgoFindMaxPairWiseProduct;
import java.util.Scanner;
public class RevisedMixedAlgoFindMaxPairWiseProduct {
public static long array[];
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = input.nextInt();
System.out.println("num:" + num);
}
}
When I compile, it shows no error. But at the time of running the program, it shows the error messages, shown in below.The message is(Netbeans's error message):
JAVA_HOME="C:\Program Files\Java\jdk-15"
cd C:\Users\Rasel Azam\Documents\NetBeansProjects\RevisedMixedAlgoFindMaxPairWiseProduct; C:\Users\Rasel Azam\.gradle\wrapper\dists\gradle-6.3-bin\8tpu6egwsccjzp10c1jckl0rx\gradle-6.3\bin\gradle --configure-on-demand -x check run
Configuration on demand is an incubating feature.
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :run FAILED
Exception in thread "main" java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at RevisedMixedAlgoFindMaxPairWiseProduct.RevisedMixedAlgoFindMaxPairWiseProduct.main(RevisedMixedAlgoFindMaxPairWiseProduct.java:28)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command 'C:\Program Files\Java\jdk-15\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
2 actionable tasks: 2 executed
But the same program is successfully run in Windows command prompt and BlueJ IDE.
I could not find what is the problem is [but while running the program, I got input buffer limit in a condition in Scanner class,is there any input buffer limit in memory in RAM] can you suggest me how can I solve this problem. For your information My PC configuration is
8GB RAM Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz 2.40 GHz Windows 10 Pro HP Probook 450 GO