I just learned Kotlin, why is this an error?

fun main() {
initMenu()
var scanner = Scanner(System.in)

var listWeapon = mutableListOf<Weapon>()
var listMagicWeapon = mutableListOf<MagicWeapon>()

var listWeapon = mutableListOf<Weapon>()
var listMagicWeapon = mutableListOf<MagicWeapon>()

}

fun initMenu() {

fun main() {
    do {
        initMenu()
        val menu = scanner.nextInt()
        scanner.nextLine()
    } while (menu !=5)
}

println("Welcome to Dungeon Store Admin Panel")
println("====================================")
println("1. Create Item")
println("2. View Item")
println("3. Update Item")
println("4. Delete Item")
println("5. Exit")
println("Choose Menu: ")

}

fun createMenu() { fun createMenu() {

} }

Can you post the error message pls?

Also it would be nice if you could format your code properly: Markdown Cheatsheet · adam-p/markdown-here Wiki · GitHub

3 Likes

Are you doing a lot of things twice:

var listWeapon = mutableListOf<Weapon>()
var listMagicWeapon = mutableListOf<MagicWeapon>()
//and then exactly the same:
var listWeapon = mutableListOf<Weapon>()
var listMagicWeapon = mutableListOf<MagicWeapon>()

create two times a main-function (once at the beginning and once inside initMenu)

creating a function createMenu inside a function createMenu

1 Like