0

What I expect: the 'for loop' brings the number of columns that will be displayed in the table, the start date, and the end date are taken by an object. the transaction date is taken by a different object. The start date variable gets the exception and the transaction date gets the value without a problem.

Code:

if(date >0){//no of dates for the selected week
    for (i in 0 until date) {
        val dateFormat = SimpleDateFormat("yyyy-MM-dd")
        val tv_Date = TextView(this)
        val transDate = SortedDateHashMap[i].transactionDate
        val start = SortedExpenseDateHashMap[i]!!.weekStart
        val end = SortedExpenseDateHashMap[i]!!.weekEnd
        val startDate = dateFormat.parse(start)
        val endDate = dateFormat.parse(end)
        var transactionDat = dateFormat.parse(transDate)
        if(transactionDat.before(endDate) && transactionDat.after(startDate)){
            setColor(tv_Date)
            tv_Date.setPadding(10, 15, 10, 10)
            tv_Date.gravity = Gravity.CENTER
            tv_Date.layoutParams = params3
            tv_Date.text = SortedDateHashMap[i].transactionDate
        }
    }
}
Mustafa Poya
  • 2,615
  • 5
  • 22
  • 36
  • What do you bean by "Kotlin Unparseable"? And for the NullPointerException: https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it – keuleJ Oct 20 '22 at 06:28
  • When I use the asserted expression the unparsable error is shown. Tried null safe as well – Habeeb Oct 20 '22 at 08:47
  • 1
    Possibly not answering what you asked, I strongly recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated, the former in particular notoriously troublesome. Instead use `LocalDate` from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) or the Kotlin equivalent. – Ole V.V. Oct 21 '22 at 00:08

1 Answers1

0

Used null safe and wrote the code in the try..catch exception. Worked