[java] Need help using the RecordStore class in J2ME programming

Started by
1 comment, last by shmoove 17 years, 5 months ago
Help!!! I have been stuck with this class for over a week now. I tried using it to save some data of my game in the mobile phone's memory but I keep getting exceptions or it doesn't save the data. I also tried looking for examples over the internet but, when I try to run those examples I get the same exceptions... Here is my code:

	static void saveGame()
	{
		byte SavedData[]=GameData.MyNoki.Name.getBytes();
		try
		{
			RecordStore SavedRecord = RecordStore.openRecordStore("TheNokiesSave",true);
			SavedRecord.addRecord(SavedData,0,GameData.MyNoki.Name.length());
			SavedRecord.closeRecordStore();
		}
		catch (Exception e)
		{
			System.out.println(e);
		}
	}

Please help me fix the method so it would work... Lots of thanks in advance to all the helpers :) P.S: Here is the explanation page of the class in Sun's Java API: http://java.sun.com/javame/reference/apis/jsr118/
Don''t have one, sorry.
Advertisement
Care to share what the exceptions are that you are getting?

Also how do you know the data isn't saved, are you sure you are reading it correctly?

There is a very useful free online book that has a chapter about RMS. The code from that book works for me. Book

You could also try J2ME Forums they are pretty active and if you search you can probably find some example code there.
One thing that I see you are doing wrong is that you are creating a new record every time you save the game. You need to test to see if the RecordStore is already there, and if it is you should only update the existing record (or at least delete the old record before you add the new one).

I don't think this has much to do with the problem you described though. On that I can only join Greig in asking what Exception are you getting?

shmoove

This topic is closed to new replies.

Advertisement