Results 1 to 4 of 4

Thread: j2me out of memory error

  1. #1
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband

    j2me 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.

    Code:
      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

    Code:
    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 = "";
     
                       }

  2. #2
    honed at getting pwned
    Join Date
    Sep 2006
    Location
    Lancashire, UK
    Posts
    449
    Thanks
    4
    Thanked
    4 times in 4 posts
    One thing I've noticed is that you are doing a lot of array manipulation without checking that you actually have any values in there.

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

    Can you guarantee that the first line of the response is at least 20 characters in length?

    You also have a couple of for loops where you expect that you have multiple lines of response, I would start debugging these sections first.

  3. #3
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband
    i've done some debugging and realize the problem lies from when i try to write the password into the outputsteam. what i done was to close all output/input streams if a user did not succed in logging in and only leave it open for when theirs a succesful login attempted made

  4. #4
    honed at getting pwned
    Join Date
    Sep 2006
    Location
    Lancashire, UK
    Posts
    449
    Thanks
    4
    Thanked
    4 times in 4 posts
    Glad you fixed it! Out of memories can be the bane of your life!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Memory Problem
    By marko in forum Help! Quick Relief From Tech Headaches
    Replies: 13
    Last Post: 10-02-2007, 04:38 PM
  2. 10% off Crucial Memory & free delivery
    By Mithrandir in forum Retail Therapy and Bargains
    Replies: 6
    Last Post: 16-01-2007, 05:10 PM
  3. The memory could not be "read" error.
    By nvisage in forum Help! Quick Relief From Tech Headaches
    Replies: 3
    Last Post: 23-04-2005, 04:38 PM
  4. Overpriced Memory Not Worth It!
    By Allen in forum PC Hardware and Components
    Replies: 26
    Last Post: 28-01-2004, 08:59 PM
  5. Memory Error?
    By yuthra253 in forum PC Hardware and Components
    Replies: 6
    Last Post: 14-01-2004, 09:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •