No Such Element Exception?

后端 未结 5 1502
南旧
南旧 2020-12-01 23:33

So here is my code:

public static void getArmor(String treasure)
    throws FileNotFoundException{
    Random rand=new Random();
    Scanner file=new Scanner         


        
5条回答
  •  有刺的猬
    2020-12-02 00:19

    I Know this question was aked 3 years ago, but I just had the same problem, and what solved it was instead of putting:

     while (i.hasNext()) {
        // code goes here 
    }
    

    I did one iteration at the start, and then checked for condition using:

    do {
       // code goes here
    } while (i.hasNext());
    

    I hope this will help some people at some stage.

提交回复
热议问题