I am trying to create a background task that runs periodically in my mains screen. I found the documentation, it seems straightforward. However, I am running into some weird behavior.
This is my class code:
open class MainMenuBackgroundTask constructor(
private val timeoutSeconds: Long,
private val mainScreenSideMenu: MainScreenSideMenu,
private val menuList: List<SideMenu.MenuItem>,
private val menuMap: MutableMap<String, Int>,
private val mainWindowService: MainWindowService,
private val progressBar: ProgressBar
) : BackgroundTask<Int, Unit>(timeoutSeconds, mainScreenSideMenu) {
@Throws(Exception::class)
override fun run(taskLifeCycle: TaskLifeCycle<Int>): Unit {
var index = 0
for (item in menuList) {
if (taskLifeCycle.isCancelled) {
break
}
menuMap[item.id] = mainWindowService.countItems(item.id)
taskLifeCycle.publish(index)
index++
}
return
}
override fun done(result: Unit) {
super.done(result)
var total = 0
for (item in menuList) {
total += mainScreenSideMenu.setMenuBadge(item)
}
ownerScreen!!.window.caption = if (total == 0) "" else "($total) Aspen"
progressBar.isVisible = false
}
override fun canceled() {
super.canceled()
progressBar.isVisible = false
}
override fun progress(changes: List<Int>) {
val lastValue = changes[changes.size - 1].toDouble()
progressBar.value = lastValue / menuList.size
}
}
And the corresponding code in the controller to create and execute the task
progressBar.isVisible = true
val task = MainMenuBackgroundTask(1000,this, menuList, menuMap,mainWindowService,progressBar)
val taskHandler: BackgroundTaskHandler<*> = backgroundWorker.handle(task)
taskHandler.execute()
I can compile it successfully, but at runtime I keep getting a ClassNotFound
exception. I have tried to separate the class into its own file, I have tried to make it an inner class of my main screen controller, and I have tried to inline it as an anonymous class. But for whatever reason, the .class
file for the class just never exists in my build directory.
I have attempted to clean
my project then compile, but I had no luck.
What could be the cause of this?