out of memory error

hi i get the above error when a user inputs a username and password in my system on the second attempt.

here is the following code: the username and password is retrieved from two textfields and stores has Strings. The username and password than gets sent back to a server and later the server will send some data telling the user that the password is incorrect or correct.

When a user logs in succesfuly at the first attempt it works but on the 2nd attempt, the program gives me a out of memory error.

public String login(String user, String pass)

{

String response =" ";

try

{

String coin_cmd ="99" +"\n"+"\0";

String coin_val ="0.1" +"\n"+"\0";

String cmd1 ="100" +"\n"+"\0";

String cmd2 ="101"+"\n"+"\0";

String p = pass +"\n"+"\0";

String u = user +"\n"+"\0";

os.write(u.getBytes());

os.flush();

os.write(p.getBytes());

os.flush();

line1[0] = getResponse();

String bad ="BADLOGIN";

String status = line1[0].substring(12,20);

if(status.equals(bad))

{

response = bad;

}

else

{

os.write(coin_cmd.getBytes());//get default coin value

os.flush();

os.write(coin_val.getBytes());

os.flush();

os.write(cmd1.getBytes());

os.flush();

os.write(cmd2.getBytes());

os.flush();

for(int i=1;i<4;i++)

{

line1[i] = getResponse();

}

//send balance

response = line1[0];

line = response;

}

}

catch(Exception e)

{

e.printStackTrace();

}

//reset it

for(int c=0; c<6 ;c++)

{

line1[c] =" ";

}

return response;

}

Below is the canvas code. Note that p and u are the password and username data gathered from the text field

line = root.login(u,p);

String bad ="BADLOGIN";

if(line.equals(bad))

{

Alert in =new Alert ("Error");

in.setString("Username or password is invalid");

in.setTimeout (3000);

Display.getDisplay(root).setCurrent(in,this);

line ="";

line1 ="";

line2 ="";

}

else

{

//display error message

Alert in =new Alert ("Logged In");

in.setString("You have succesfuly logged into the system");

in.setTimeout (3000);

Display.getDisplay(root).setCurrent(in,this);

loggedIn =true;

logged ="Log out";

//line = "";

line1 ="";

line2 ="";

}

[4481 byte] By [jonney69a] at [2007-11-27 2:01:30]
# 1
hi is their any suggestions please? i tried using System.gc(); before i begin a new write but i still get the out of memory error
jonney69a at 2007-7-12 1:41:39 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Try to use the WTK Memory Monitor (Preferences/Monitor) to find the black hole in your app.
rhoerninga at 2007-7-12 1:41:39 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

i've debugged and found out where the problem occurs. its in the second os.write statement os.write(p.getBytes());

how can solve that problem? i need to send the p varaible into the server which represents the password. i have tried typing in just one character for username and password and i still get an out of memory error.

I've also tried the WTK trick but the program wont appear on the emulator. i am currently building the program using netbeans 5.5

jonney69a at 2007-7-12 1:41:39 > top of Java-index,Java Mobility Forums,Java ME Technologies...