Hvordan sætter jeg en klasse ind?
Jeg er ved at lave en MIDlet, og vil bruge RMS.Til det har jeg fundet følgende klasse hvorfra jeg kan bruge RMS:
import java.io.*;
import javax.microedition.rms.*;
public class Record implements DataInput {
private RecordStore _rs;
private byte[] _data;
private int _length;
private int _id;
private DataInputStream _din;
public Record( RecordStore rs ){
this( rs, 100 );
}
public Record(
RecordStore rs, int initialRecordSize ){
_rs = rs;
_data = new byte[ initialRecordSize ];
_din = new DataInputStream(
new ByteArrayInputStream( _data ) );
_length = -1;
}
public byte[] getByteArray() { return _data; }
public int getLength() { return _length; }
public byte[] moveTo( int id )
throws RecordStoreNotOpenException,
InvalidRecordIDException,
RecordStoreException,
IOException
{
_length = _rs.getRecordSize( id );
if( _length > _data.length ){
_data = new byte[ _length + 40 ];
_din = new DataInputStream(
new ByteArrayInputStream( _data ) );
}
_rs.getRecord( id, _data, 0 );
_id = id;
_din.reset();
return _data;
}
public void readFully(byte b[])
throws IOException {
_din.readFully( b );
}
public void readFully(byte b[], int off, int len)
throws IOException {
_din.readFully( b, off, len );
}
return _din.skipBytes( n );
}
public boolean readBoolean() throws IOException {
return _din.readBoolean();
}
public byte readByte() throws IOException {
return _din.readByte();
}
public int readUnsignedByte()
throws IOException {
return _din.readUnsignedByte();
}
public short readShort() throws IOException {
return _din.readShort();
}
public int readUnsignedShort()
throws IOException {
return _din.readUnsignedShort();
}
public char readChar() throws IOException {
return _din.readChar();
}
public int readInt() throws IOException {
return _din.readInt();
}
public long readLong() throws IOException {
return _din.readLong();
}
public String readUTF() throws IOException {
return _din.readUTF();
}
}
Problemet er bare, at den hele tiden melder tilbage 'class' or 'interface' expected.
Det project jeg arbejder ud fra er
import java.io.*;
import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class TestStore
extends MIDlet
implements CommandListener
{
private Form mMainForm;
public TestStore()
{
mMainForm = new Form("Min første MIDlet");
mMainForm.append(new StringItem(null, "hello world"));
mMainForm.addCommand(new Command("Afslut", Command.EXIT, 0));
mMainForm.setCommandListener(this);
}
public void startApp()
{
Display.getDisplay(this).setCurrent(mMainForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s)
{
notifyDestroyed();
}
}
Hvordan får jeg klassen sat ind i mit projekt?
Kilde:
http://developers.sun.com/techtopics/mobility/midp/ttips/rmsbasics/