This site requires JavaScript, please enable it in your browser!
Greenfoot back
erdelf
erdelf wrote ...

2012/6/21

UserInfo gets me an error

erdelf erdelf

2012/6/21

#
hello, when my world loads, it gaves me the error ArrayIndexOutOfBoundsException: 1 , at line 36 here: if(UserInfo.isStorageAvailable()) { UserInfo playerData = UserInfo.getMyInfo(); // this is line 36 userImg = playerData.getUserImage(); userImage = true; }
davmac davmac

2012/6/22

#
Can you post the full stack trace?
erdelf erdelf

2012/6/22

#
It is in both world classes of my stargate space shooter. here are error and method. here is the error:
java.lang.ArrayIndexOutOfBoundsException: 1
	at greenfoot.platforms.ide.GreenfootUtilDelegateIDE$1.compare(GreenfootUtilDelegateIDE.java:404)
	at greenfoot.platforms.ide.GreenfootUtilDelegateIDE$1.compare(GreenfootUtilDelegateIDE.java:399)
	at java.util.Arrays.mergeSort(Arrays.java:1270)
	at java.util.Arrays.sort(Arrays.java:1210)
	at java.util.Collections.sort(Collections.java:159)
	at greenfoot.platforms.ide.GreenfootUtilDelegateIDE.getAllDataSorted(GreenfootUtilDelegateIDE.java:399)
	at greenfoot.platforms.ide.GreenfootUtilDelegateIDE.getCurrentUserInfo(GreenfootUtilDelegateIDE.java:260)
	at greenfoot.util.GreenfootUtil.getCurrentUserInfo(GreenfootUtil.java:887)
	at greenfoot.UserInfo.getMyInfo(UserInfo.java:234)
	at Endless.<init>(Endless.java:36)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at greenfoot.core.Simulation.newInstance(Simulation.java:578)
	at greenfoot.platforms.ide.WorldHandlerDelegateIDE$3.run(WorldHandlerDelegateIDE.java:408)
	at greenfoot.core.Simulation.runQueuedTasks(Simulation.java:465)
	at greenfoot.core.Simulation.maybePause(Simulation.java:279)
	at greenfoot.core.Simulation.runContent(Simulation.java:210)
	at greenfoot.core.Simulation.run(Simulation.java:203)
and here the method:
    public Endless()
    {    
        super(1000, 600, 1); 
        GreenfootImage background = new GreenfootImage(1000, 600);
        scrollingImage = getScrollingImage(1000, 600);
        background.drawImage(scrollingImage, 0, 0);
        setBackground(background); 
        if(UserInfo.isStorageAvailable())  
        {
            UserInfo playerData = UserInfo.getMyInfo();
            userImg = playerData.getUserImage();
            userImage = true;
        } else
        {
            userImage = false;
        }
        setPaintOrder(ScoreBoard.class, JumperShield.class, Jumper.class, Enemies.class, Enemies_attack.class, HPBar.class, HWBar.class, LWBar.class, Explosion.class,Drone.class, N_bomb.class, Powerup.class);
        addObject(hpbar, getWidth() / 2, 20);
        addObject(lwbar, getWidth() / 2, 40);
        addObject(hwbar, getWidth() / 2, 60);
        addObject(shbar, getWidth() / 2, 80);
        addObject(jumper, 43, 314);
        Greenfoot.start();
        opening.play();
    }
trash1000 trash1000

2012/6/22

#
        if(UserInfo.isStorageAvailable()) {
            if(UserInfo.getMyInfo() != null) {
                UserInfo playerData = UserInfo.getMyInfo();
                userImg = playerData.getUserImage();
                userImage = true;
            }
        } 
UserInfo.isStorageAvailable() only tells you, whether your scenario is run on the greenfoot.org website. UserInfo.getMyInfo() will return null when you aren't logged in to greenfoot.org so you should check for this as well. I always do it like that, so it should work.
erdelf erdelf

2012/6/22

#
now it marks your new line, same error
        if(UserInfo.isStorageAvailable())  
        {
            if(UserInfo.getMyInfo() != null)  // this line is marked
            { 
                UserInfo playerData = UserInfo.getMyInfo();
                userImg = playerData.getUserImage();
                userImage = true;
            } else
            {
                userImage = false;
            }
        } else
        {
            userImage = false;
        }
trash1000 trash1000

2012/6/22

#
You could try to delete storage.csv from your scenario's folder and then try it again. There is nothing wrong with the code, at least I don't see it.
erdelf erdelf

2012/6/22

#
ok. thx it works now
nccb nccb

2012/6/23

#
@erdelf: trash1000's suggestion was correct. This error can only occur if the storage.csv file gets messed up. Can you tell me: did you manually edit it at all, or did this problem come about solely from Greenfoot writing/reading that file?
erdelf erdelf

2012/6/23

#
I manually edited it, I changed 20 to 200. Another question; Is it needed that I delete the storage.csv before uploading?
nccb nccb

2012/6/23

#
@erdelf: The storage mechanism online is totally separate from the CSV. So the online scores won't be affected by the CSV being present. But I did just check, and your storage.csv does get uploaded as part of the scenario! So when other users open it in Greenfoot, they will get your storage.csv. Hmmm, not sure if that's a bug or a feature!
You need to login to post a reply.