Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 561
ΩlostA Avatar asked Mar 06 '19 07:03

ΩlostA


3 Answers

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

like image 144
Ensar Bayhan Avatar answered Nov 16 '22 15:11

Ensar Bayhan


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

like image 4
michael ditrick Avatar answered Nov 16 '22 16:11

michael ditrick


This error can show up if you have defined any object outside of class declaration

example :
class someActivity extands something{ } private someMethod(){}

to solve this just move it inside

`class someActivity extands something{

private someMethod(){} }`

like image 1
Hamid Raza Goraya Avatar answered Nov 16 '22 15:11

Hamid Raza Goraya