2

1.エミュレーターの問題: 最初に midlet
アプリを起動してデータを保存し、2 回目に再起動して保存されたデータを読み取ります。最初の 2 つのケースでは、例外なくうまく機能しています。

ただし、同じ方法で2回再起動すると、「Uncaught exception java/lang/NumberFormatException:」という例外が発生します。これはcharのみを処理しており、合計データは64 kb未満です。

2. 実機の問題:
RMS がまったく機能していません。ハンドセット (nokia n95) に許可を与える必要があるかどうかわかりません。

ありがとう。


アプリでは、選択した国に応じて慈善団体を rms に保存するだけです。そのため、国がすでに選択されている場合は、国のリストをスキップして、再起動するたびに会社のリストを表示する必要があります。以下のコードでは、rms_Check() メソッドは、国または企業のリスト フレームを開くためにデータをチェックすることです。

public class X {

private static RecordStore rs =null;
private static Vector rms_Vector = new Vector();
static final String REC_STORE ="db_1";

public X() {

}

public void openRecStore(){
    try {
        rs = RecordStore.openRecordStore(REC_STORE, true);
        System.out.println("open record store");
    } catch (Exception e)
    {
        db(e.toString()+" in openRecStore");
    }
}

public void closeRecStore(){
    try {
        rs.closeRecordStore();
    } catch (Exception e) {
        db(e.toString()+" in closeRecStore");
    }
}

public void deleteRecStore()
{
if (RecordStore.listRecordStores()!=null){
    try {
        RecordStore.deleteRecordStore(REC_STORE);
    } catch (Exception e) {
        db(e.toString()+" in deleteRecStore");
    }
}
}

public void writeRecord(String str) throws UnsupportedEncodingException
{
    byte[] rec = str.getBytes("UTF-8");

    try {
        rs.addRecord(rec, 0, rec.length);
        System.out.println("write record store");
    } catch (Exception e) {
        db(e.toString()+" in writeRecord");
    }
}

public void readRecord()
{
    try {
        // Intentionally it is too small to test code 
        byte[] m_enc = new byte[5];
        byte[] recData = new String(m_enc).getBytes("UTF-8");
        int len;

        for(int i =1; i<= rs.getNumRecords(); i++){
        if(rs.getRecordSize(i)> recData.length)
            recData = new byte[rs.getRecordSize(i)];

        len = rs.getRecord(i, recData, 0);
        System.out.println("Record #"+i+":"+new String(recData, 0, len));
        System.out.println("------------------------");
        rms_Vector.addElement(new String(recData, 0, len));
        }
    } catch (Exception e) {
        db(e.toString() +" in readStore");
    }
}

private void db(String str)
{
System.out.println("Msg:"+str);
}
public Vector rms_Array(){

    return this.rms_Vector;
}

public boolean rms_Check(){
if(this.rms_Vector.size()>0){
    System.out.print("rms_check: true");
    // if true it will display company list every time
return true;
}else{
    System.out.print("rms_check: false");
    //if false it will display country list then company list
return false;
}
}

}
4

1 に答える 1

1

これを使って

private RecordStore rs = null;    // Record store
public String REC_STORE = "RSM name"; // Name of record store
public int record_max=0;

public void openRecStore(){
try{
rs = RecordStore.openRecordStore(REC_STORE, true );
}catch (Exception e){}
}  

 public void closeRecStore(){
try{
rs.closeRecordStore();
}catch (Exception e){}
}

public void deleteRecStore(){
if (RecordStore.listRecordStores() != null){
try{
RecordStore.deleteRecordStore(REC_STORE);
}catch (Exception e){}
}  
}

public void writeRecord(String str){
byte[] rec = str.getBytes();

 try{
 rs.addRecord(rec, 0, rec.length);
 }catch (Exception e){}
 }

  public void readRecords(){
   try{
   byte[] recData = new byte[5]; 
    int len;
    record_max=rs.getNumRecords();
    for(int i = 1; i <= record_max; i++){

        if(rs.getRecordSize(i) > recData.length){
        recData = new byte[rs.getRecordSize(i)];

        }
        len = rs.getRecord(i, recData, 0);
        file_name[i]=new String(recData, 0, len);

       }
     }catch (Exception e){}
   }

セーブデータの file_name[] 配列があります

load actin コマンドの使用:

            openRecStore();
            readRecords();
            for(int j=1;j<=record_max;j++ ) {
             System.out.println("Record " + j + " : " + file_name[j]);
                }
             closeRecStore();

これを保存します:

            openRecStore();
            writeRecord(textField.getString());
            closeRecStore();
于 2012-06-23T15:29:50.887 に答える