0

我想在 a 中使用整数值TextField。在下面的代码中,我将整数值从表中检索到textfield3. 当我使用getInteger(2)它时会出错。那么有什么替代方案。如果解析是解决方案(例如.toString)如何在这种方法中实现?

TextField3 = new TextField("Amount: ",r.getString(2));
add(TextField3);

这正是我想要做的

try
{
    //Open or create the database
    Database db = DatabaseFactory.openOrCreate("database1.db");    

    //Retrieval
    Statement statement1 = db.createStatement("SELECT date,name,amount,narration FROM Bills where id='"+TextField00.getText()+"'");
    //This is one text field to accept id value
    statement1.prepare();
    statement1.execute();

    Cursor c = statement1.getCursor();
    Row r;

    while(c.next())
    {
        r = c.getRow();
        TextField5 = new TextField("Date: ",r.getString(0));
        add(TextField5); 

        TextField2 = new TextField("Customer Name: ",r.getString(1));
        add(TextField2);

        TextField3 = new TextField("Amount: ",r.getString(2));
        add(TextField3);

        TextField4 = new TextField("Narration: ",r.getString(3));
        add(TextField4);
    }

    //statement1.prepare();
    //statement1.execute();       
    statement1.close(); 
    db.close();
}
catch( Exception e ) 
{         
    System.out.println( e.getMessage() );
    e.printStackTrace();
}

希望对您的理解有所帮助。

4

2 回答 2

0

试试这条线

TextField3 = new TextField("Amount: ", r.getInteger(2) + "");

代替

TextField3 = new TextField("Amount: ",r.getString(2));
于 2012-04-25T16:23:24.253 回答
0

您可以使用java.lang.Integer.toString()

TextField3 = new TextField("Amount: ", Integer.toString(r.getInteger(2)));
于 2012-04-25T22:08:23.497 回答