no grabar datos en el recordset
Publicado por felipe largacha (18 intervenciones) el 03/03/2011 18:15:42
Estoy haciendo uan aplicacion en java pa celular j2me pero no entiendo porque al ejecutar el codigo aveces se pueden guardar registros y a veces no se deja.
que esta pasando
cualquier ayuda gracias
NOTA: EN AL OTRA HOAJA ESTA EL RESTO DE CODIGO
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
public class HighRecord extends MIDlet implements CommandListener
{
Form form, form1, form2, form3, form4;
Command c1, c2, c3, c4, c5, c6,cClearAllRecord;
RecordStore rs;
ByteArrayOutputStream bosStream;
DataOutputStream dos;
byte[] dat;
TextField t1, t2;
String[] tempString;
int[] tempInt;
public HighRecord()
{
try
{
rs = RecordStore.openRecordStore("HighRecord",true);
bosStream = new ByteArrayOutputStream();
}
catch (RecordStoreFullException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
tempInt = new int[3];
tempString = new String[3];
form = new Form("menu");
c1 = new Command("new", Command.SCREEN, 1);
c2 = new Command("edit", Command.SCREEN, 1);
c3 = new Command("mod3000mod", Command.SCREEN, 1);
c4 = new Command("borrar", Command.SCREEN, 1);
cClearAllRecord = new Command("Borrar Todos Los REGISTROS", Command.SCREEN,1);
form.addCommand(c1);
form.addCommand(c2);
form.addCommand(c3);
form.addCommand(c4);
form.addCommand(cClearAllRecord);
form.setCommandListener(this);
form1 = new Form("formulario");
t1 = new TextField("nombre", "", 30, TextField.ANY);
t2 = new TextField("password", "", 30, TextField.NUMERIC);
form1.append(t1);
form1.append(t2);
c5 = new Command("Guardar", Command.SCREEN,1);
form1.addCommand(c5);
form1.setCommandListener(this);
c6 = new Command("Salir", Command.SCREEN,1);
/*
* t1 = new TextField("hola","",30,TextField.ANY); t2 = new
* TextField("password","",30,TextField.NUMERIC); form2.addCommand(c5);
*/
form.setCommandListener(this);
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
// TODO Auto-generated method stub
}
protected void pauseApp()
{
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
/*
* myFilter mf=new myFilter(); try { RecordEnumeration iter =
* rs.enumerateRecords(mf, null, true); } catch
* (RecordStoreNotOpenException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
// RecordEnumeration iter = rs.enumerateRecords(mf, new SortDescend(),
// true);
// TODO Auto-generated method stub
}
public void commandAction(Command arg0, Displayable arg1)
{
// TODO Auto-generated method stub
if ( arg0 == c1 )
{
t1.setString("");
t2.setString("");
Display.getDisplay(this).setCurrent(form1);
}
if ( arg0 == c2 )
{
form2 = new Form("form2");
form2.addCommand(c6);
form2.setCommandListener(this);
form2.append("REGISTROS\n");
try
{
rs = RecordStore.openRecordStore("HighRecord",true);
for ( int i = 1; i < rs.getNumRecords(); i++ )
{
byte dat[] = rs.getRecord(i);
ByteArrayInputStream bis = new ByteArrayInputStream(dat);
DataInputStream dis = new DataInputStream(bis);
String name = dis.readUTF();
int score = dis.readInt();
form2.append(name + "" + score + "\n");
}
rs.closeRecordStore();
//
}
catch (Exception e)
{
}
Display.getDisplay(this).setCurrent(form2);
}
que esta pasando
cualquier ayuda gracias
NOTA: EN AL OTRA HOAJA ESTA EL RESTO DE CODIGO
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.rms.InvalidRecordIDException;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
import javax.microedition.rms.RecordStoreFullException;
import javax.microedition.rms.RecordStoreNotFoundException;
import javax.microedition.rms.RecordStoreNotOpenException;
public class HighRecord extends MIDlet implements CommandListener
{
Form form, form1, form2, form3, form4;
Command c1, c2, c3, c4, c5, c6,cClearAllRecord;
RecordStore rs;
ByteArrayOutputStream bosStream;
DataOutputStream dos;
byte[] dat;
TextField t1, t2;
String[] tempString;
int[] tempInt;
public HighRecord()
{
try
{
rs = RecordStore.openRecordStore("HighRecord",true);
bosStream = new ByteArrayOutputStream();
}
catch (RecordStoreFullException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (RecordStoreException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
tempInt = new int[3];
tempString = new String[3];
form = new Form("menu");
c1 = new Command("new", Command.SCREEN, 1);
c2 = new Command("edit", Command.SCREEN, 1);
c3 = new Command("mod3000mod", Command.SCREEN, 1);
c4 = new Command("borrar", Command.SCREEN, 1);
cClearAllRecord = new Command("Borrar Todos Los REGISTROS", Command.SCREEN,1);
form.addCommand(c1);
form.addCommand(c2);
form.addCommand(c3);
form.addCommand(c4);
form.addCommand(cClearAllRecord);
form.setCommandListener(this);
form1 = new Form("formulario");
t1 = new TextField("nombre", "", 30, TextField.ANY);
t2 = new TextField("password", "", 30, TextField.NUMERIC);
form1.append(t1);
form1.append(t2);
c5 = new Command("Guardar", Command.SCREEN,1);
form1.addCommand(c5);
form1.setCommandListener(this);
c6 = new Command("Salir", Command.SCREEN,1);
/*
* t1 = new TextField("hola","",30,TextField.ANY); t2 = new
* TextField("password","",30,TextField.NUMERIC); form2.addCommand(c5);
*/
form.setCommandListener(this);
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
// TODO Auto-generated method stub
}
protected void pauseApp()
{
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException
{
Display.getDisplay(this).setCurrent(form);
/*
* myFilter mf=new myFilter(); try { RecordEnumeration iter =
* rs.enumerateRecords(mf, null, true); } catch
* (RecordStoreNotOpenException e) { // TODO Auto-generated catch block
* e.printStackTrace(); }
*/
// RecordEnumeration iter = rs.enumerateRecords(mf, new SortDescend(),
// true);
// TODO Auto-generated method stub
}
public void commandAction(Command arg0, Displayable arg1)
{
// TODO Auto-generated method stub
if ( arg0 == c1 )
{
t1.setString("");
t2.setString("");
Display.getDisplay(this).setCurrent(form1);
}
if ( arg0 == c2 )
{
form2 = new Form("form2");
form2.addCommand(c6);
form2.setCommandListener(this);
form2.append("REGISTROS\n");
try
{
rs = RecordStore.openRecordStore("HighRecord",true);
for ( int i = 1; i < rs.getNumRecords(); i++ )
{
byte dat[] = rs.getRecord(i);
ByteArrayInputStream bis = new ByteArrayInputStream(dat);
DataInputStream dis = new DataInputStream(bis);
String name = dis.readUTF();
int score = dis.readInt();
form2.append(name + "" + score + "\n");
}
rs.closeRecordStore();
//
}
catch (Exception e)
{
}
Display.getDisplay(this).setCurrent(form2);
}
Valora esta pregunta


0