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

2012/3/22

What? Scenario not loading when uploaded?

1
2
3
4
TheNightStrider TheNightStrider

2012/3/22

#
java.lang.NoClassDefFoundError: Editor$Recipe at Editor.<init>(Editor.java:64) at GameWorld.<init>(GameWorld.java:117) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at greenfoot.export.GreenfootScenarioViewer.instantiateNewWorld(GreenfootScenarioViewer.java:310) at greenfoot.export.GreenfootScenarioViewer.init(GreenfootScenarioViewer.java:215) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: Editor$Recipe at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 10 more java.lang.NoClassDefFoundError: Editor$Recipe at Editor.<init>(Editor.java:64) at GameWorld.<init>(GameWorld.java:117) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at greenfoot.export.GreenfootScenarioViewer.instantiateNewWorld(GreenfootScenarioViewer.java:310) at greenfoot.platforms.standalone.WorldHandlerDelegateStandAlone.instantiateNewWorld(WorldHandlerDelegateStandAlone.java:80) at greenfoot.core.WorldHandler.instantiateNewWorld(WorldHandler.java:509) at greenfoot.actions.ResetWorldAction.resetWorld(ResetWorldAction.java:89) at greenfoot.actions.ResetWorldAction.actionPerformed(ResetWorldAction.java:79) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$000(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.awt.EventQueue$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.awt.EventQueue$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) I get that? Anyone got any clue? This is my code-breaker entry and the deadline is tomorrow!
TheNightStrider TheNightStrider

2012/3/22

#
No offence guys, but I NEED a lightning quick response! The deadline for this is tomorrow! The Editor was a major feature!
TheNightStrider TheNightStrider

2012/3/22

#
Somebody! Please! I need help!
danpost danpost

2012/3/23

#
Whatever it is, is happening at line 64 in your Editor constructor code. Post your code to the constructor of the Editor class. (You are referencing a class that it cannot find there)
TheNightStrider TheNightStrider

2012/3/23

#
That was my immediate reaction, but that is only the error I get when create a jar; not when i run in greenfoot. Nonetheless: at 64
 public Recipe[] r = new Recipe[]{new Recipe(),new Recipe(), new Recipe(),new Recipe()};
but the thing is in the exact same class, i do this
 public class Recipe{
        String ina;
        String inb;
        String out;
        Recipe(){
            ina="";
            inb="";
            out="";}
    }    
TheNightStrider TheNightStrider

2012/3/23

#
So basically I really don't know why that is happening at all? It runs fine in greenfoot but not on the scenarios page or in a jar. That doesn't make sense to me because asides, it works fine when using the greenfoot apllication
danpost danpost

2012/3/23

#
Try changing line 64 to
 public Recipe[] r = {new Recipe(),new Recipe(), new Recipe(),new Recipe()};
TheNightStrider TheNightStrider

2012/3/23

#
Sorry, it didn't change a thing. I will repeat, it works fine in Greenfoot but not when I have uploaded it or when I have exported it to jar. Weird..... Thanks - I appreciate you replying! Also, line 64 is NOT inside the constructor
danpost danpost

2012/3/23

#
TheNightStrider wrote...
Also, line 64 is NOT inside the constructor
I see! It did not quite make it that far.
TheNightStrider TheNightStrider

2012/3/23

#
Okay.... Any suggestions?
danpost danpost

2012/3/23

#
I guess I would have to see all of the Recipe class code to get a better idea of what is going on.
TheNightStrider TheNightStrider

2012/3/23

#
danpost wrote...
I guess I would have to see all of the Recipe class code to get a better idea of what is going on.
I won't leave it up for too long though!
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.io.*; //required for input/output text files
/**
 * Create your own puzzles!
 * 
 * @MrinankSharma
 * @21/03/2012
 */
public class Editor extends World
{
    public class Object{
        String image;
        int x;
        int y; 
        String added;
        Object(){
            image="disable";    
            x=0;
            y=0;
            added="nothing";
        }
    }    
     public class Recipe{
        String ina;
        String inb;
        String out;
        Recipe(){
            ina="";
            inb="";
            out="";}
    }    
    private String[] levels = new String[]{"levelone.txt","leveltwo.txt","levelthree.txt"};
    GameWorld gw=null;
    BufferedWriter w = null;
    private int currentbg=0;
    public InteractiveObjects[]Wo =new  InteractiveObjects[]{new  InteractiveObjects(),new  InteractiveObjects(), new  InteractiveObjects(), new  InteractiveObjects()};
    private Button addRecipe = (Button) new Button();
    private Button returnGame = (Button) new Button();
    private Button createPuzzle=(Button) new Button();
    private Button changeBg = (Button) new Button();  
    private Button a = (Button) new Button();
    private Button b = (Button) new Button();
    private Button c = (Button) new Button();
    private Button d = (Button) new Button();
    private Button proceed = (Button) new Button();
    private Button aI = (Button) new Button();
    private Button bI = (Button) new Button();
    private Button cI = (Button) new Button();
    private Button dI = (Button) new Button();
    private Button info = (Button) new Button();
    public Object[] objectsInWorld = new Object[]{new Object(),new Object(),new Object(),new Object()};
    private String[] posObjects = new String[]{"disable","brokenDesk","computer","door","FuelCanisterWorld",
            "sewer","table","body"};
    private String[] posIObjects = new String[]{"nothing","BoxOfMatches","Diamonds","DiamondCutter","FuelCanister",
            "key","keyMould","paperClip","PolyPropyleneBlock","ReadyThermite"
        ,"sharpWoodRod","Thermite","welder","woodBlock",} ;
    private int stage=0;
    private String[] IO= new String[4];
    private String[] posBackground = new String[]{"start.png","final.png","sewerlevel.png","tutorial.png"};                                              
    private int apos,bpos,cpos,dpos=0;
    private int aIpos,bIpos,cIpos,dIpos=0;
    private boolean origrun=true;
   public Recipe[] r = {new Recipe(),new Recipe(), new Recipe(),new Recipe()}; 
    private int rn=0;
    private int mx,my=0;
    private Text eText=null;
    private boolean loaded=false;
    public boolean ininventm=false;
    public String[] inventHeld;
    private int pos=0;
    Button p1 = (Button) new Button();
    Button p2 = (Button) new Button();
    Button p3 = (Button) new Button();
    private boolean slotChosen=false;
    public Editor(GameWorld world)
    {    
        super(640, 480, 1); 
        setBackground("editor.png");
        addObject(createPuzzle,146,355);
        addObject(returnGame,146,385);
        createPuzzle.which("CREATE NEW PUZZLE");
        returnGame.which("RETURN TO GAME");
        gw=world;

    }

    public void act(){
        if(Greenfoot.mouseClicked(returnGame)){Greenfoot.setWorld(gw);}
        if(Greenfoot.mouseClicked(createPuzzle)){removeObject(createPuzzle);
            removeObjects(getObjects(Button.class));
            addObject(p1,146,355); 
            addObject(p2,146,385);
            addObject(p3,146,415);
            p1.which("SLOT 1");
            p2.which("SLOT 2");
            p3.which("SLOT 3");
        }
        if(Greenfoot.mouseClicked(p1)){pos=1;removeObjects(getObjects(Button.class));origrun=true;stage=1;}
        if(Greenfoot.mouseClicked(p2)){pos=2;removeObjects(getObjects(Button.class));origrun=true;stage=1;}
        if(Greenfoot.mouseClicked(p3)){pos=3;removeObjects(getObjects(Button.class));origrun=true;stage=1;}
        if(Greenfoot.mouseClicked(proceed)){stage++;origrun=true;}
        switch(stage){
            case 1:if(origrun){stageOne();origrun=false;createPuzzle.which("CONTINUE");}
            if(Greenfoot.mouseClicked(changeBg)){if(currentbg==3){currentbg=0;}else{currentbg++;}changeBg.setImage(posBackground[currentbg]); changeBg.scale();}
            break;
            case 2:
            if(origrun){stageTwo();origrun=false;}
            checkClicks();
            break;
            case 3:if(origrun){ ;stageThree();origrun=false;}
            checkClicksB();break;
            case 4: if(origrun){stageFour();origrun=false;}checkClicksC();
            case 5: if(origrun){stageFive();origrun=false;} checkClicksD();
            case 6: if(origrun){stageFinal();}break;
        }

    }

    public void stageOne(){
        setBackground("escreenone.png");
        addObject(proceed,66,360);
        addObject(changeBg,420,280);
        changeBg.setImage(posBackground[currentbg]);
        changeBg.scale();
        proceed.reSize(110,25);
        proceed.which("PROCEED");
    }

    public void stageTwo(){
        removeObject(changeBg);
        setBackground("escreentwo.png");
        addObject(a,94,274);
        addObject(b,239,274);
        addObject(c,384,274);
        addObject(d,538,274);
        a.setImage(posObjects[apos]+".png");
        b.setImage(posObjects[bpos]+".png");
        c.setImage(posObjects[cpos]+".png");
        d.setImage(posObjects[dpos]+".png"); 
    }

    public void stageThree(){
        if(posObjects[dpos]!="disable"&&(posObjects[apos]!="disable"||posObjects[bpos]!="disable"||posObjects[cpos]!="disable")){
            setBackground("escreenthree.png");
            objectsInWorld[0].image=posObjects[apos];
            objectsInWorld[1].image=posObjects[bpos];
            objectsInWorld[2].image=posObjects[cpos];
            objectsInWorld[3].image=posObjects[dpos];
            addObject(aI,91,320);
            addObject(bI,289,320);
            addObject(cI,452,320);
            addObject(dI,576,320);
            a.setLocation(91,214);
            b.setLocation(289,214);
            c.setLocation(452,214);
            d.setLocation(576,214);
            aI.setImage(posIObjects[aIpos]+".png");
            bI.setImage(posIObjects[bIpos]+".png");
            cI.setImage(posIObjects[cIpos]+".png");
            dI.setImage(posIObjects[dIpos]+".png"); 
        }
        else{stage=2;}
    }

    public void stageFour(){
        if(posIObjects[dIpos]!="nothing"){
            apos=0;bpos=0;cpos=0;
            setBackground("escreenfour.png");
            objectsInWorld[0].added=posIObjects[aIpos];
            objectsInWorld[1].added=posIObjects[bIpos];
            objectsInWorld[2].added=posIObjects[cIpos];
            objectsInWorld[3].added=posIObjects[dIpos];
            for(int i=0;i<=3;i++){
                if(objectsInWorld[i].added!="nothing.png"){IO[i]=objectsInWorld[i].added;}
                else{IO[i]="";}
            }
            removeObjects(getObjects(Button.class));
            addObject(proceed,66,360); 
            proceed.which("PROCEED");
            addObject(a,233,197);
            addObject(b,233,255);
            addObject(c,565,225);
            addObject(addRecipe,360,360);
            a.setSize(275,25);
            b.setSize(275,25);
            c.setSize(275,25);
            a.which(IO[apos]);
            b.which(IO[bpos]);
            c.which(posIObjects[cpos]);
            addRecipe.which("ADD RECIPE");
        }
        else
        {stage=3;}
    }    

    public void checkClicks(){    
        if(Greenfoot.mouseClicked(a)){apos++;a.setImage(posObjects[apos]+".png");if(apos==7){apos=-1;}}
        if(Greenfoot.mouseClicked(b)){bpos++;b.setImage(posObjects[bpos]+".png");if(bpos==7){bpos=-1;}}
        if(Greenfoot.mouseClicked(c)){cpos++;c.setImage(posObjects[cpos]+".png");if(cpos==7){cpos=-1;}}
        if(Greenfoot.mouseClicked(d)){dpos++;d.setImage(posObjects[dpos]+".png");if(dpos==7){dpos=-1;}}
    }

    public void checkClicksB(){
        if(Greenfoot.mouseClicked(aI)&&objectsInWorld[0].image!="disable.png"){aIpos++;aI.setImage(posIObjects[aIpos]+".png");if(aIpos==13){aIpos=-1;}}
        if(Greenfoot.mouseClicked(bI)&&objectsInWorld[1].image!="disable.png"){bIpos++;bI.setImage(posIObjects[bIpos]+".png");if(bIpos==13){bIpos=-1;}}
        if(Greenfoot.mouseClicked(cI)&&objectsInWorld[2].image!="disable.png"){cIpos++;cI.setImage(posIObjects[cIpos]+".png");if(cIpos==13){cIpos=-1;}}
        if(Greenfoot.mouseClicked(dI)&&objectsInWorld[3].image!="disable.png"){dIpos++;dI.setImage(posIObjects[dIpos]+".png");if(dIpos==13){dIpos=-1;}}
    }

    public void checkClicksC(){//need to edit
        if(Greenfoot.mousePressed(a)){if(apos>1){apos=0;}else{apos++;}a.which(IO[apos]);}
        if(Greenfoot.mousePressed(b)){if(bpos>1){bpos=0;}else{bpos++;}b.which(IO[bpos]);}
        if(Greenfoot.mousePressed(c)){if(cpos>12){cpos=0;}else{cpos++;}c.which(posIObjects[cpos]);}
        if(Greenfoot.mousePressed(addRecipe)&&(posIObjects[cpos]!=IO[apos])&&(posIObjects[cpos]!=IO[bpos])
        && IO[apos]!=IO[bpos] && IO[apos]!="nothing" && IO[bpos]!="nothing" && posIObjects[cpos]!="nothing" && rn<4  
        && isItThere()){
            r[rn].ina=IO[apos];
            r[rn].inb=IO[bpos];
            IO[apos]=posIObjects[cpos];
            IO[bpos]="";
            r[rn].out=posIObjects[cpos];
            //System.out.println(r[rn].ina + ";" +r[rn].inb+";"+r[rn].out);
            rn++;
        }
    }

    public void checkClicksD(){
        if(Greenfoot.mouseDragged(Wo[0])){getM();Wo[0].setLocation(mx,my);}
        if(Greenfoot.mouseDragged(Wo[1])){getM();Wo[1].setLocation(mx,my);}
        if(Greenfoot.mouseDragged(Wo[2])){getM();Wo[2].setLocation(mx,my);}
        if(Greenfoot.mouseDragged(Wo[3])){getM();Wo[3].setLocation(mx,my);}
    }

    public void stageFive()
    {
        if(isItThere()){
            removeObjects(getObjects(Button.class));
            setBackground(posBackground[currentbg]);
            addObject(proceed,100,90);
            addObject(info,400,90);
            for(int i=0;i<=3&&objectsInWorld[i].image!="disable.png";i++){
                addObject(Wo[i],320,400);Wo[i].setImage(objectsInWorld[i].image+".png");}
            proceed.which("PROCEED");
            info.which("DRAG + DROP OBJECTS");}
        else
        {
            stage=4;
            rn=0;
        }
    }

    public void getM(){
        if(Greenfoot.getMouseInfo()!=null){
            mx=Greenfoot.getMouseInfo().getX();
            my=Greenfoot.getMouseInfo().getY();
            if(my<320){mx=320;my=400;}}else{mx=320;my=400;} 
    } 

    public void stageFinal(){
        stage=-1;
        removeObjects(getObjects(Button.class)); 
        for(int i=0;i<=3;i++){
            objectsInWorld[i].x=Wo[i].getX();
            objectsInWorld[i].y=Wo[i].getY();
        }
        saveLevel();   
        setBackground("editor.png");
        removeObjects(getObjects(Button.class)); 
        addObject(createPuzzle,146,355);
        addObject(returnGame,146,385);
        createPuzzle.which("CREATE NEW PUZZLE");
        returnGame.which("RETURN TO GAME");
        Greenfoot.setWorld(gw);
    }

    public void saveLevel(){
        try{
            write(pos-1);
        }catch(IOException e){}
        catch(SecurityException s){}

    }

    public void write(int a)throws IOException{
        File f = new File(levels[a]);
        f.createNewFile();
        w=new BufferedWriter(new FileWriter(f));
        for(int i=0; i<=3; i++){
            w.write(objectsInWorld[i].image+";");
            w.write(objectsInWorld[i].x+";");
            w.write(objectsInWorld[i].y+";");
            w.write(objectsInWorld[i].added+";");
        }
        for(int i=0;i<=3;i++){
            w.write(r[i].ina+";");
            w.write(r[i].inb+";");
            w.write(r[i].out+";");
        }
        w.write(posBackground[currentbg]);
        w.close();  
    }

    public boolean isItThere(){ 
        for(int i=0;i<=3;i++){
            if(IO[i].equals(objectsInWorld[3].added)){return true;}
        }
        return false;
    }

 
}
Thanks for the help alot!
TheNightStrider TheNightStrider

2012/3/23

#
danpost wrote...
I guess I would have to see all of the Recipe class code to get a better idea of what is going on.
I have just put it up! (Sorry if my programming is aweful. :-))
TheNightStrider TheNightStrider

2012/3/23

#
I can't see what is wrong!
TheNightStrider TheNightStrider

2012/3/23

#
Anybody?
There are more replies on the next page.
1
2
3
4