×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    12

    Stuck in addRecord coding

    Hi,

    I am stuck in adding records to record store.
    My purpose is to add Subject and Section into one record in recordstore.
    Below is part of my coding:

    try {
    String[] Note = {Subject.getString(),Section.getString()};
    //If new record, recId = 0
    addRecord(0, Note);
    } catch (IOException ex) {
    ex.printStackTrace();
    }

    ...
    ...

    private void addRecord(int recId, String[] record) throws IOException {
    // Add records to recordStore
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream dout = new DataOutputStream(bout);
    for(int i=0; i < record.length; i++) {
    dout.writeUTF(record[i].getSubject()); <--- ERROR encountered.
    dout.writeUTF(record[i].getSection()); <--- ERROR encountered.
    }
    dout.close();
    byte[] data = bout.toByteArray();
    try {
    RecordStore store = RecordStore.openRecordStore("NoteLibrary", true);
    if (recId == 0)
    recId = store.addRecord(data, 0, data.length);
    else
    store.setRecord(recId, data, 0, data.length);
    store.closeRecordStore();
    } catch (RecordStoreNotOpenException e) {
    e.printStackTrace();
    } catch (RecordStoreFullException e) {
    e.printStackTrace();
    } catch (RecordStoreException e) {
    e.printStackTrace();
    }
    }

    Please advise.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Code:
    DataOutputStream dout = new DataOutputStream(bout);
    for(int i=0; i < record.length; i++) {
        dout.writeUTF(record[i]);
    }
    dout.close();
    Just change the lines to the one above. Your String array has a length of 2. [0] is your subject. [1] is your section. More about Java arrays (which are a bit confusing) in the Java Tutorial&#160;…

  3. #3
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Re: Stuck in addRecord coding

    checkout the code running perfectly. By the way what error r u facing? Please mention that. Might be the problem is recId.
    When u send recId = 0 then program runs ok but when u send RecId = value other than 0 or 1 like 2 or 3 then u are facing problem coz recordId is not exist when u set the record at recId = 2 or 3. Its just my guess. Please mention the exception comes if any.

    Code:
    private void addRecord(int recId) {
    // Add records to recordStore
    
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(bout);
            try {
                dout.writeUTF("Jitendra");
                dout.writeUTF("Agarwal");
    
                dout.close();
                byte[] data = bout.toByteArray();
    
                RecordStore store = RecordStore.openRecordStore("NoteLibrary", true);
                if (recId == 0) {
                    recId = store.addRecord(data, 0, data.length);
                } else {
                    store.setRecord(recId, data, 0, data.length);
                }
                store.closeRecordStore();
            } catch (RecordStoreNotOpenException e) {
                e.printStackTrace();
            } catch (RecordStoreFullException e) {
                e.printStackTrace();
            } catch (RecordStoreException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. Efficient C coding.
    By cabezonxdg in forum Symbian
    Replies: 4
    Last Post: 2007-07-26, 14:06
  2. Replies: 7
    Last Post: 2007-05-01, 17:38
  3. Problem on reading "SMS coding scheme"
    By fran24 in forum General Messaging
    Replies: 0
    Last Post: 2006-12-19, 08:03
  4. Coding Problem
    By honeyzan in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2003-06-23, 08:16
  5. insert SMIL coding into java
    By Land96 in forum General Messaging
    Replies: 0
    Last Post: 2002-08-24, 03:22

Posting Permissions

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