AC Solution submitted on codechef running on my netbeans ide... but when tried to check my soltuon codechef ide on "Code, Compile and Run" its giving following error

problem link
why when submitting My answer using Scanner it got accepted but when i tried codechef ide by Code, Compile and Run" Section of Practice… it is giving error as follow–

Exception in thread “main” java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076) at MARCHA2.main(Main.java:23)

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Hemant Dhanuka
 */
class MARCHA2 {

    static int totalAmount, noOfCoins;
    static int[] coinValue;
    static boolean exist = false;

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int noOfCases = s.nextInt();
        for (int i = 0; i < noOfCases; i++) {
            noOfCoins = s.nextInt();
            totalAmount = s.nextInt();
            coinValue = new int[noOfCoins];
            for (int j = 0; j < noOfCoins; j++) {

                coinValue[j] = s.nextInt();

            }
            //int[] booleanArray=new int[noOfCoins];
            // Integer[] booleanArray=new Integer[noOfCoins];
            //      List<Integer> booleanArrayList = Arrays.stream(booleanArray).boxed().collect(Collectors.toList());  
            //ArrayList<Integer> booleanArrayList=new ArrayList<>(Arrays.asList(booleanArray));
            ArrayList<Integer> al = new ArrayList<>(noOfCoins);
            for (int p = 0; p < noOfCoins; p++) {
                al.add(0);
            }
            exist = false;
            check(al, -1);
            if (exist) {
                System.out.println("Yes");
            } else {
                System.out.println("No");

            }
        }
    }

    private static int check(ArrayList<Integer> al, int count) {
        int sum = 0;
        count++;

        for (int i = 0; i < noOfCoins; i++) {
            if (al.get(i) == 1) {
                sum = sum + coinValue[i];
            }

        }
        if (sum == totalAmount) {
            exist = true;
            return 0;
        }
        if (sum > totalAmount) {
            return 0;
        }
        if (count == noOfCoins) {
            return 0;
        }
        ArrayList<Integer> newal = new ArrayList<>();
        for (int b = 0; b < al.size(); b++) {
            newal.add(al.get(b));
        }
        newal.set(count, 1);
        return check(al, count) + check(newal, count);
    }
}

[Getting Scanner Class Error in Java][1]

Basically, from what I see, is that it occurs as-

java.util.NoSuchElementException 
indicates that you have no more elements presents in Scanner

To fix this, keep a check of

if(s1.hasNextInt()){
    win[i]=s1.nextInt();
}

Why it got accepted in submission while giving error in “Code Compile and Run” might be because of some differences in the two compilers. I am not sure, but Codechef uses SPOJ type compiler for submissions and I think your format is acceptable to it.
[1]: java.util.scanner - Getting Java Scanner class error - Stack Overflow

I got ac with the same solution

https://www.codechef.com/viewsolution/12938904

Okay, this is strange. Even I got Scanner exception when I ran, but SUDDENLY the same code is giving correct output with no errors. IDK what happened XD.

I just executed in codechef’s ide it is running completely fine.

Yeah, he is referring to the code he posted in previous thread of his. This code runs fine.

yes it is giving AC answer but when u run it on “Code, Compile and Run” codechef ide its giving following error, i don’t know why
Exception in thread “main” java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at MARCHA2.main(Main.java:23)

is this now code giving correct output to codechef practice compiler??

Yes, it has stopped giving me exception on same code. This is weird, but anyways, i am glad that at least you DID solve the problem

earlier may be u r not providing input and directly tring to run code…

Lol. No dear, I did provide input. Anyways, problem fixed itself on opening a new tab.