Value Conversion had Date in sqlite Android error The method getText () is undefined for the type String

1

I'm doing the insertion of a DATE type value in my project, so I had to convert it, in my corresponding class, my tribute Dt_read, it is declared as string and in the database it is as Date. For this, at the moment I'm inserting the record in the database, I'm converting it, as below:

public Consumo inserir (Consumo consumo){

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    dateFormat.applyPattern("yyyy-MM-dd");
    Date data =  (Date) dateFormat.parse(consumo.dt_leitura.getText());  


        ContentValues valores = new ContentValues();

        valores.put("dt_leitura",dateFormat.format(data));  
        valores.put("registro", consumo.getRegistro());

        consumo.setId(db.insert("consumo", null, valores ));
        return consumo;


}

Only in the stretch

Date data =  (Date) dateFormat.parse(consumo.dt_leitura.getText());

You are returning the following error:

  

The method getText () is undefined for the type String

Could you tell me if I'm also doing the correct date conversion?

    
asked by anonymous 31.10.2015 / 19:24

1 answer

1

The error says that the String class has no method with the name getText

The method parse() of the class SimpleDateFormat receives a String, as you say in the question, the consumo.dt_leitura attribute is a String, so pass it directly to method parse() :

Date data =  (Date) dateFormat.parse(consumo.dt_leitura);
    
31.10.2015 / 19:42