I am new to android developement. I am making a simple expense management program in which there are 2 buttons; one to save the reciever, date and amount records and other button to view these records.Here is the part of the main code that i wrote:
public class database {
public static final String DBNAME = "dbexpense";
SQLiteDatabase db;
DBHandler handler;
public database(Context ctx) {
handler = new DBHandler(ctx);
}
class DBHandler extends SQLiteOpenHelper {
public DBHandler(Context ctx) {
super(ctx, DBNAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table expenses(id integer primary key autoincrement,from text,dated date, amount number );");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists expenses");
onCreate(db);
}
}
public void open() {
db = handler.getWritableDatabase();
}
public void close() {
db.close();
}
public boolean saveRecord(String from, Date dated, Number amount)
{
ContentValues cv=new ContentValues();
cv.put("From", from);
cv.put("Dated", dated);
cv.put("Amount", amount);
return db.insert("expenses", "", cv)>0;
}
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText2"
android:inputType="date">
</EditText>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText3"
android:inputType="number"></EditText>
My xml file has edit text fields for date & number.
This shows an error : The method put(String, String) in the type ContentValues is not applicable for the arguments (String, Date) and The method put(String, String) in the type ContentValues is not applicable for the arguments (String, Number). Is there any other way to save?
Convert your values to the expected format before you try to store them.
E.g String.ValueOf(number) to convert a number to a string.