problem in retrieving data via RMS

Reply

Join Date: Jul 2009
Posts: 44
Reputation: Dajer is an unknown quantity at this point 
Solved Threads: 2
Dajer Dajer is offline Offline
Light Poster

problem in retrieving data via RMS

 
0
  #1
Aug 30th, 2009
hi friends...
I have Written some codes for adding and retrieving data from RMS:
  1. public void commandAction(Command command, Displayable displayable) {
  2. if(command==exit)
  3. {
  4. destroyApp(true);
  5. notifyDestroyed();
  6. }
  7. else if(command==start)
  8. {
  9. try
  10. {
  11. recordstore=RecordStore.openRecordStore("My RecordStore",true);
  12. }
  13. catch(Exception error)
  14. {
  15. alert=new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
  16. alert.setTimeout(Alert.FOREVER);
  17. display.setCurrent(alert);
  18. }
  19. try
  20. {
  21. String outPutData[]={"Mary","Bob","Adam"};
  22. for(int x=0;x<3;x++)
  23. {
  24. byte[] byteOutPutData=outPutData[x].getBytes();
  25. recordstore.addRecord(byteOutPutData,0,byteOutPutData.length);
  26. }
  27. }
  28.  
  29. catch(Exception error)
  30. {
  31. alert=new Alert("Error Waiting",error.toString(),null,AlertType.WARNING);
  32. alert.setTimeout(Alert.FOREVER);
  33. display.setCurrent(alert);
  34. }
  35. try
  36. {
  37. byte[] byteInputData=new byte[1];
  38. int length=0;
  39. for(int x=1;x<=recordstore.getNumRecords();x++)
  40. {
  41. if(recordstore.getRecordSize(x)>byteInputData.length)
  42. {
  43. byteInputData=new byte[recordstore.getRecordSize(x)];
  44. }
  45. length=recordstore.getRecord(1,byteInputData,0);
  46. }
  47. alert = new Alert("Reading", new String(byteInputData, 0,length), null, AlertType.WARNING);
  48. alert.setTimeout(Alert.FOREVER);
  49. display.setCurrent(alert);
  50.  
  51.  
  52. }
  53. catch (Exception error)
  54. {
  55. alert = new Alert("Error Reading", error.toString(),null, AlertType.WARNING);
  56. alert.setTimeout(Alert.FOREVER);
  57. display.setCurrent(alert);
  58. }
  59. try
  60. {
  61. recordstore.closeRecordStore();
  62. }
  63. catch (Exception error)
  64. {
  65. alert = new Alert("Error Closing", error.toString(),null, AlertType.WARNING);
  66. alert.setTimeout(Alert.FOREVER);
  67. display.setCurrent(alert);
  68. }
  69. if (RecordStore.listRecordStores() != null)
  70. {
  71. try
  72. {
  73. recordstore.deleteRecordStore("MY RecordStore");
  74. }
  75. catch (Exception error)
  76. {
  77. alert = new Alert("Error Removing", error.toString(),null, AlertType.WARNING);
  78. alert.setTimeout(Alert.FOREVER);
  79. display.setCurrent(alert);
  80. }
  81. }
  82. }
  83. }

but when i run it , instead of my record i see this error :
Attached Thumbnails
Error.JPG  
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 121
Reputation: puneetkay is on a distinguished road 
Solved Threads: 23
puneetkay's Avatar
puneetkay puneetkay is offline Offline
Junior Poster

Re: problem in retrieving data via RMS

 
1
  #2
Aug 30th, 2009
  1. public void commandAction(Command command, Displayable displayable) {
  2. if(command==exit)
  3. {
  4. destroyApp(true);
  5. notifyDestroyed();
  6. }
  7. else if(command==start)
  8. {
  9. try
  10. {
  11. recordstore=RecordStore.openRecordStore("My RecordStore",true); // LINE 1
  12. }
  13. catch(Exception error)
  14. {
  15. alert=new Alert("Error Creating",error.toString(),null,AlertType.WARNING);
  16. alert.setTimeout(Alert.FOREVER);
  17. display.setCurrent(alert);
  18. }
  19. try
  20. {
  21. String outPutData[]={"Mary","Bob","Adam"};
  22. for(int x=0;x<3;x++)
  23. {
  24. byte[] byteOutPutData=outPutData[x].getBytes();
  25. recordstore.addRecord(byteOutPutData,0,byteOutPutData.length);
  26. }
  27. }
  28.  
  29. catch(Exception error)
  30. {
  31. alert=new Alert("Error Waiting",error.toString(),null,AlertType.WARNING);
  32. alert.setTimeout(Alert.FOREVER);
  33. display.setCurrent(alert);
  34. }
  35. try
  36. {
  37. byte[] byteInputData=new byte[1];
  38. int length=0;
  39. for(int x=1;x<=recordstore.getNumRecords();x++)
  40. {
  41. if(recordstore.getRecordSize(x)>byteInputData.length)
  42. {
  43. byteInputData=new byte[recordstore.getRecordSize(x)];
  44. }
  45. length=recordstore.getRecord(1,byteInputData,0);
  46. }
  47. alert = new Alert("Reading", new String(byteInputData, 0,length), null, AlertType.WARNING);
  48. alert.setTimeout(Alert.FOREVER);
  49. display.setCurrent(alert);
  50.  
  51.  
  52. }
  53. catch (Exception error)
  54. {
  55. alert = new Alert("Error Reading", error.toString(),null, AlertType.WARNING);
  56. alert.setTimeout(Alert.FOREVER);
  57. display.setCurrent(alert);
  58. }
  59. try
  60. {
  61. recordstore.closeRecordStore();
  62. }
  63. catch (Exception error)
  64. {
  65. alert = new Alert("Error Closing", error.toString(),null, AlertType.WARNING);
  66. alert.setTimeout(Alert.FOREVER);
  67. display.setCurrent(alert);
  68. }
  69. if (RecordStore.listRecordStores() != null)
  70. {
  71. try
  72. {
  73. recordstore.deleteRecordStore("MY RecordStore"); // LINE 2
  74. }
  75. catch (Exception error)
  76. {
  77. alert = new Alert("Error Removing", error.toString(),null, AlertType.WARNING);
  78. alert.setTimeout(Alert.FOREVER);
  79. display.setCurrent(alert);
  80. }
  81. }
  82. }
  83. }

Check "Line 1" and "Line 2" tags.

"My RecordStore" and "MY RecordStore" both are different names.

Theres no RS with name "MY RecordStore". Thats why its showing error.

Regards,
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer


Admin of Pikk - Object Relational Mapping Framework
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC