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

2016/10/1

java.lang.OutOfMemoryError: HOW CAN I SOLVE IT

dimpap5555 dimpap5555

2016/10/1

#
java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:714) at Rocket.Controls(Rocket.java:42) at Rocket.act(Rocket.java:20) at greenfoot.core.Simulation.actActor(Simulation.java:604) at greenfoot.core.Simulation.runOneLoop(Simulation.java:562) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) Can you help me i dont know how to beacause i am beginer
danpost danpost

2016/10/1

#
The error appears to be occurring in the Rocket class (although, with this type of error, the problem may be anywhere). First, however, post your entire Rocket class (including imports).
dimpap5555 dimpap5555

2016/10/2

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class Rocket here. * * @author (your name) * @version (a version number or a date) */ public class Rocket extends Actor { /** * Act - do whatever the Rocket wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ MouseInfo mouse = Greenfoot.getMouseInfo(); public void act() { Controls(); } private void Controls() { Thread ctl = new Thread() { public void run() { while(true) { if(Greenfoot.mouseClicked(getWorld())) //null = any click, not only on this object { if(Greenfoot.mouseDragged(getWorld())) { MouseInfo mouse = Greenfoot.getMouseInfo(); setLocation(mouse.getX(), getY()); //set y to mouse y, not x } } } } }; ctl.start(); } } but now i have an other problem it says in the error log that: JDWP exit error AGENT_ERROR_INVALID_EVENT_TYPE(204): ExceptionOccurred
Super_Hippo Super_Hippo

2016/10/2

#
What are you doing there? Remove the 'thread' thing and the method in the method and the while loop.
danpost danpost

2016/10/2

#
You should avoid using the Thread class in greenfoot. Also, greenfoot does the initial looping for you that creates the running of the simulation. So, a 'run' method is not needed. As such, you do not program for the life of the actor, but for each instance the actor exists. What this means is that you can remove the 'while(true)' condition. The 'Controls' method would then be:
private void Controls()
{
    if (Greenfoot.mouseDragged(this))
    {
        setLocation(getX(), Greenfoot.getMouseInfo().getY());
    }
}
The comment at the end of the 'setLocation' line says to keep the x and change the y to mouse y, so I took the liberty to adjust the code.
dimpap5555 dimpap5555

2016/10/3

#
Thank you very much guys if i have new problems i will inform you again
You need to login to post a reply.