Shop OBEX P1 Docs P2 Docs Learn Events
error with program in javelin — Parallax Forums

error with program in javelin

JamesJames Posts: 15
edited 2006-11-09 19:00 in General Discussion
I'm recieving this [noparse][[/noparse]error IDE-0028] unhandled exception in JVM:Java.lang.OutOfMemoryError.........is there a clear way of solving this issue software wise or is it done by hardware. when running through the debug there is 22Kbytes of free space...

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 18:27
    Please post your code.
    regards peter
  • JamesJames Posts: 15
    edited 2006-11-09 18:46
    import stamp.core.*;
    import stamp.math.*;
    import stamp.util.text.*;
    import stamp.peripheral.appmod.LcdTerminal;

    public class TemperatureAD592_highres2 {
    · public static void main() {
    ··· int myVar,frac,frac1,Dec2,Tc,Tk,chargeTicks,I1,I2,I3,F1,F2;
    ··· int Tf;
    ··· int dispChar;
    ··· String sTc, sTf, sfrac1,soutput;
    ··· LcdTerminal display = new LcdTerminal();
    ··· StringBuffer msg = new StringBuffer();



    ····· CPU.writePin(CPU.pin8,false); //discharge C
    ····· CPU.delay(10);
    ····· chargeTicks = CPU.rcTime(32767,CPU.pin8,true);· //measure time needed to reach 2.5V
    ····· I1 = 31682/chargeTicks;
    ····· F1 = UnsignedIntMath.ufrac(31682,chargeTicks); //calculate 65536 based fraction
    ····· I2 = UnsignedIntMath.udiv(F1,(short)32768);
    ····· F2 = UnsignedIntMath.ufrac(F1,(short)32768); //calculate 65536 based fraction
    ····· frac = UnsignedIntMath.frac2dec(F2); //convert to 10000 based fraction
    ····· I3 = UnsignedIntMath.udiv(9,5);
    ····· Tk = 2*I1 + I2+10; //integer part of Tk
    ····· Tc = Tk - 273;
    ····· Tf = (I3)*Tc+32;
    ····· frac1 = UnsignedIntMath.frac2dec(Tf);
    ····· sTc= Integer.toString(Tc);
    ····· sTf= Integer.toString(Tf);
    ····· sfrac1= Integer.toString(frac1);
    ····· soutput= sTf +"."+ sfrac1;
    ···· /* Format.printf("Temp in Kelvin : %d.",Tk);
    ····· Format.printf("%02d\n",frac/100);
    ····· Format.printf("Temp in Celsius: %d.",Tc);
    ····· Format.printf("%02d\n",frac/100);
    ····· Format.printf("Temp in Farenheit: %d.",Tf);
    ····· Format.printf("%02d\n",frac1/100); */
    ···· while(true){
    ····· display.clearScr();
    ··· Button b1 = new Button(CPU.pin10, true);
    ··· Button b2 = new Button(CPU.pin11, true);
    ··· Button b3 = new Button(CPU.pin12, true);
    ··· Button b4 = new Button(CPU.pin13, true);
    ··· if ( b1.buttonDown() )
    ···· {
    ····· msg.clear();
    ····· msg.append("Farenheit");
    ····· display.scroll(display.LINE1, msg);
    ····· display.moveTo(display.LINE2, 2);
    ····· display.write(soutput);
    ····· CPU.delay(30000);
    ····· Format.printf("Temp in Farenheit: %d.",Tf);
    ····· Format.printf("%02d\n",frac1/100);
    ····· }
    ··· if ( b2.buttonDown() )
    ···· {
    ····· msg.clear();
    ····· msg.append("pH Level");
    ····· display.scroll(display.LINE1, msg);
    ····· display.moveTo(display.LINE2, 2);
    ····· display.write(soutput);
    ····· CPU.delay(3000);
    ····· }
    ··· if ( b3.buttonDown() )
    ···· {
    ····· msg.clear();
    ····· msg.append("Celcius");
    ····· display.scroll(display.LINE1, msg);
    ····· display.moveTo(display.LINE2, 2);
    ····· display.write(soutput);
    ····· CPU.delay(3000);
    ····· }
    ··· if ( b4.buttonDown() )
    ···· {
    ····· msg.clear();
    ····· msg.append("Kelvin");
    ····· display.scroll(display.LINE1, msg);
    ····· display.moveTo(display.LINE2, 2);
    ····· display.write(soutput);
    ····· CPU.delay(3000);
    ····· }
    · }
    · }
    }
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2006-11-09 19:00
    The problem is the
    ··· Button b1 = new Button(CPU.pin10, true);
    ··· Button b2 = new Button(CPU.pin11, true);
    ··· Button b3 = new Button(CPU.pin12, true);
    ··· Button b4 = new Button(CPU.pin13, true);

    You create·4 new Button objects, each time through the while (true) loop.
    Remember the javelin has no garbage collection, hence no memory
    is ever reclaimed. So you must avoid using the new keyword in·the mainloop.
    If you don't, you will eventually run out of memory, as you experienced.

    regards peter
Sign In or Register to comment.