• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Returning a String from a Method

Ovalman

Lurker
Hi all, first post so go easy on me. I've been trying to program for 3+ years now and still very much a Noob.

I'm trying to return a date as a string but I keep getting a null value.

I've tried several different ways to fix this without any success. I know it's something simple I'm doing wrong but I can't put my finger on it. Any help would be appreciated.

getDateTime();
balanceToDatabase(balance, strId);
helper.insertIntoPaid(strId, amountpaid, dateTime, "Notes Paid", "Spare 1", "Spare 2", "Spare 3"); //insert into paid table


btnPaid.setClickable(false); // so paid button can't be pressed again to avoid mistakes

Toast.makeText((getApplicationContext()), "£" + amountpaid + " paid has been recorded!", Toast.LENGTH_SHORT).show();
}

public void balanceToDatabase (String amountResultStr, String strId){
ContentValues newValues = new ContentValues();
newValues.put("balance", amountResultStr);
SQLiteDatabase db= helper.getWritableDatabase();
db.update("customers", newValues, "_id="+ strId, null);
db.close();
}

public String getDateTime() {
Calendar c = Calendar.getInstance();

SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String dateTime = df.format(c.getTime());
// formattedDate have current date/time
Toast.makeText(this, dateTime, Toast.LENGTH_SHORT).show();

return dateTime;
}
 
Think I sorted it myself.

String dateTime = df.format(c.getTime()).toString;

It was being used as a local variable, hence the toast pop up but not being passed back as a String.

I ran it in debugger and everything seems OK but I won't know until I write some more code to extract the string from my database again.
 
Back
Top Bottom