1

I'm developing a small J2ME application that displays bus stops timetables - they are stored as records in MIDP RecordStores.

Sometimes records can not fit a single RecordStore, especially on record update - using setRecord method - a RecordStoreFullException occurs. I catch the exception, and try to write the record to a new RecordStore along with deleting the previous one in the old RecordStore. Everything works fine except of deleting record from RecordStore where the RecordStoreFullException occurs. If I make an attempt to delete record that could not be updated, another Exception of type InvalidRecordIDException is thrown. This is weird and undocumented in MIDP javadoc. I have tested it on Sun WTK 2.5.2, MicroEdition SDK 3.0 and Nokia Series 40 SDK. Furthermore I created a code that reproduces this strange behaviour:


RecordStore rms = null;
        int id = 0;
        try {
            rms  = RecordStore.openRecordStore("Test", true);
            byte[] raw = new byte[192*10024]; //Big enough to cause RecordStoreFullException
            id = rms.addRecord(raw, 0, 160);
            rms.setRecord(id, raw, 0, raw.length);
        } catch (Exception e) {
            try {
                int count = rms.getNumRecords();
                RecordEnumeration en = rms.enumerateRecords(null, null, true);
                count = en.numRecords();
                while(en.hasNextElement()){
                    System.out.println("NextID: "+en.nextRecordId());
                }
                rms.deleteRecord(id); //this won't work!
                rms.setRecord(id, new byte[5], 0, 5); //this won't work too!
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

I added extra enumeration code to produce other weird behavior - when RecordStoreFullException occurs, count variable will be set to 1 (if RMS was empty) by both methods - getNumRecords and numRecords. System.out.println will produce NextID: 0! It is not acceptable because record ID can not be 0! Could someone explain this strange behavior?

Sorry for my bad English.

4

1 に答える 1

0

本当にsetRecord投げRecordStoreFullExceptionますか?

addRecordthrows RecordStoreFullExceptionthenidが更新されず、 をしようとしている場合deleteRecord(0)InvalidRecordIDException.

Enumeration コードは、Sun と Nokia の両方の RMS の実装における実際のバグを示しているように思えます (Series40 が KVM を長い間使用していたため、これは同じものである可能性があります)。https://phoneme.dev.java.net/にある Sun の実装のソース コードを調べることで、それを特定できる場合があります (まだ存在すると仮定します) 。

Symbian によって開発された RMS の実装が含まれているため、Series60 電話で同じことを試すことをお勧めします。

于 2010-03-17T12:25:52.833 に答える