如何将整数转换为文本以供在textfield java-blackberry中使用

时间:2012-04-25 14:02:26

标签: parsing blackberry

我想在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();
}

希望它能帮助你理解。

2 个答案:

答案 0 :(得分:0)

试试这一行,

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

而不是

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

答案 1 :(得分:0)

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

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