2

So, I wanted to implement a simple database handler class for my Android Studio project with Kotlin. Little did I know when I eye-rolled towards my "what even is kotlin" developer mates, that this hipster choice would lead me to lengthy damnation.
I decided to start out by copy-pasting the code Google suggests for a DB Helper utilizing the SQLiteOpenHelper class.

Naturally, I started getting this unreasonable error
enter image description here
for each of the closing brackets } in 3 different methods containing what looked like perfectly valid syntax.
enter image description here

Of course, I spent over a day checking every single piece of annoying Gradle build property that seems to be there only to increase the chances of something being off, as if it were a perfectly designed developer-Limbo build system from Hell. But every little check was to no avail, as I had no build errors and the "Expecting member" errors kept showing up.

Decided not to quit however, I even attempted to change my implementation to use the more Kotlin-friendly anko.db route, full code below.

package com.example.john.myapplication

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import org.jetbrains.anko.db.*

class DBHandler(context: Context) : ManagedSQLiteOpenHelper(context, "POIEncounters", null, 1) {

    override fun onCreate(db: SQLiteDatabase?) {
        db?.createTable("Encounter", true, "id" to INTEGER + PRIMARY_KEY + UNIQUE, "Name" to TEXT)
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.dropTable("Encounter", true)
    }

    override fun onDowngrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        onUpgrade(db, oldVersion, newVersion)
    }

}

As Divine Order dictates in the Developer Limbo, there was no change at all. Every time I click Build I am fooled by the syntax checker's underhanded reassurances, as the compiler denies my salvation. Even more amazingly. the errors persist even if I comment-out the entire bodies of the overridden methods.

At this point I am so beyond despair that I have fallen to the lowest level of the abyss: rejecting my ego and asking for help.

jathanasiou
  • 882
  • 2
  • 8
  • 17

1 Answers1

4

For those not brave enough to witness the process, TLDR at the end.

The answer is given by my own self, after 3 endless epochs (see: days) in this unbuildable hellish dimension, and written at 3am with the sole company of a bottle of Glenfiddich whisky joined in the dark by the sounds of my demonized keyboard clacking.

The usual suspects of easy-to-miss spelling errors, invalid constructor usage have been discarded over and over as I descend into madness, now fairly certain that even if someone where to copy my exact code, they might not even be getting this error.

I even tried tried downgrading Kotlin itself, in delusional hopes of a bug in its compiler bringing forth all these insistent mutterings of "Expecting declaration"...
In a last insane attempt I even tried importing my code into a different infernal machination of an IDE, just to see if the apocryphal messages would follow me there, in Intellij IDEA...

After one more hour of torment to align the new project's build files and other horrid properties causing minor issues... They did.
enter image description here

I was about to give up and when I spotted this strange, unfamiliar sign on Intellij's syntax checker: Found byte-order-mark in the middle of a file <...> enter image description here

SON. OF. A. BENCH.

Now, at this incredibly agonizing part of my journey, much like many other devs living in the blissful heaven-like area of "typing code that is parsed the way you read it", I had no forking idea what a BOM is.

Yet the celestial IDEA even gives us the forbidden, dark knowledge of a wikipedia link, which I followed in foolish innocence, to see a maddening, curious fragment of the cosmos which man was not meant to lay eyes upon...
enter image description here

What the fork.

My fingers trembled and started moving in a feverish climax. I heard myself cackling as I submerged myself in the unreal madness of a last irrational hope...

I deleted the 3 methods. Purged them all an in unholy, functio-cidal frenzy and gazed up the empty class, free of the invisible, sickening infection.

Build. *click* Success.


I rewrote each and every one one of the methods by hand, without copy-pasting or touching any devil-infected piece of vile text, while listening to the fiendish, otherworldly "Dethklok Awaken" calls. And that was it. It worked. I am free, ascending into Elysium, whiskey in one hand and tears dropping to the Flame Below.
Yet, empty and disappointed. For the the cunning shade was not a tangible foe, but an ephemeral force, looming inside the Self...
With this answer, I hope no one has to face the same mistake I did. Not unprepared at least.


TLDR: There was a BOM character that was causing the error. Intellij clarified the cause, while Android Studio didn't. Deleted and re-wrote problematic parts by hand without copy-pasting anything and it worked.

Epilogue: Everyday we stray further from ASCII's light.

jathanasiou
  • 882
  • 2
  • 8
  • 17