• Advertisement
Sign in to follow this  

Strange Java Exception

This topic is 3577 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I keep getting "java.util.NoSuchElementException" returned to me for this section of code but I can not see any reason why it is happening. I've gone through and checked the areas where there might be a problem but I dont know where to being. I think it is throwing an exception because it is accessing something that hasn't been created yet everything works fine when I run the code. I really am a loss as to why this is happening. Here is the code if anyone thinks they can figure it out.
   public void loadAnimations(String w)throws Exception{
        
        try{
            Scanner sc3 = new Scanner(new FileReader("Worlds/"+world+"/Objects/"+w+"/info.dat"));
            while (sc3.hasNextLine()){
                String disposable2 = sc3.next();
                
                if (disposable2.equals("o")){
                    
                    disposable2 = sc3.next();
                    BufferedImage objImg = ImageIO.read(new File("Worlds/"+world+"/Objects/"+w+"/"+disposable2));
                    
                    if (getPrefix(disposable2).equals("default")){
                        objMass = 0;
                        for (int i = 0;i<objImg.getWidth();i++ ){
                            for (int i2 = 0;i2<objImg.getHeight();i2++ ){
                                int alpha = (objImg.getRGB(i, i2) >> 24) & 0xff;
                                if (alpha != 0) {
                                    objMass++;

                                }}}}
                    
                    objectAnimMap.put(w +getPrefix(disposable2)+0,objImg);
                    sc3.nextLine();
                    
                } else if (disposable2.equals("s")){
                    int tmpInt = sc3.nextInt();
                    disposable2 = sc3.next();
                    BufferedImage objImg = ImageIO.read(new File("Worlds/"+world+"/Objects/"+w+"/"+disposable2));
                    for (int i = 0; i<tmpInt;i++){
                        BufferedImage tmp = objImg.getSubimage((objImg.getWidth()/tmpInt)*i,0,objImg.getWidth()/tmpInt,objImg.getHeight());
                    }}}sc3.close();
        }catch (Exception ex){
            System.out.println(ex+"@Gamepanel.loadAnimations");
        }}


[Edited by - NotTheCommonDose on April 3, 2008 3:25:29 PM]

Share this post


Link to post
Share on other sites
Advertisement
Edit your post and put your code in ['source']['/source'] tags (minus the '). Also, if you're using any IDE it should tell you the line number that the error is occurring.

Quote:

I think it is throwing an exception because it is accessing something that hasn't been created yet everything works fine when I run the code


How can it work fine if you're getting this error?

Share this post


Link to post
Share on other sites
I think it's a non-fatal error. It's returning the error because I have it in a catch statement, what it's referring to it does not tell me. That is the extent of the message, there is no line being returned.

Share this post


Link to post
Share on other sites
RESOLVED: The problem is the while sc.hasNextLine(), I narrowed it down and replaced that with a sc.hasNext(), the error went away. Thank you.

James

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement