Android/Kotlin: Error: "Expecting a top level declaration > Task :app:buildInfoGeneratorDebug"

36,045

Solution 1

I just delete the last curly brace and write it again. It's working :)

Solution 2

The same happened to me, you just need to remove an auto-generated extra curly bracket at the end, then it works.

Share:
36,045
ΩlostA
Author by

ΩlostA

Développer iOS/Android at NewTelApps

Updated on September 05, 2021

Comments

  • ΩlostA
    ΩlostA over 2 years

    I try to write a class to manage a SQLite DB, but I have the error message "Expecting a top level declaration > Task :app:buildInfoGeneratorDebug".

       package com.xexxxwxxxxs.GMP
    
        import android.database.sqlite.SQLiteDatabase
        import android.database.sqlite.SQLiteOpenHelper
        import android.content.Context
        import android.content.ContentValues
    
        class DBHandler(context: Context, name: String?, factory: SQLiteDatabase.CursorFactory?, version: Int) : SQLiteOpenHelper(context, DATABASE_NAME, factory, DATABASE_VERSION)
        {
            override fun onCreate(db: SQLiteDatabase)
            {
    
            }
    
            override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int)
            {
    
            }
    
            companion object
            {
                private val DATABASE_VERSION = 1
                private val DATABASE_NAME = "GMP.db"
            }
        } 
    

    Do you have any ideas?

    Thanks in advance

  • ΩlostA
    ΩlostA about 5 years
    You just killed me :D It works. Incredible... It seems that there is a invisble character at the end.
  • pallav bohara
    pallav bohara almost 4 years
    In my case there was an extra closing braces
  • Syed Arsalan Kazmi
    Syed Arsalan Kazmi almost 3 years
    Just when I though that there is no place for black magic in the coding. hehe. Thanks.
  • Richard Kirk
    Richard Kirk almost 2 years
    I had a slightly fancier version: I had to delete the last three brackets and put them back in again.