Search code examples
javaandroidclasscontract

Accessing class private members from another class


I'm new to programming, and I'm starting with Java and Android. I want to create a database, so I've followed the offical documentation: https://developer.android.com/training/basics/data-storage/databases.html

My problem comes when, on the Contract class, the members to create and maintain the database are private strings (SQL_CREATE_ENTRIES and SQL_DELETE_ENTRIES). Defining the DBHelper class on another file, I just cannot access that members the way it appears on the documentation (the FeedReaderDbHelper class just use them as if they were inside it scope). So Android Studio just put the sentence on red and says: 'Cannot resolve symbol'.

What should I do here? I've read as well on the documentation that setters/getters are not recommended for Android.


Solution

  • Put SQL_CREATE_ENTRIES and SQL_DELETE_ENTRIES in the DBHelper class.

    From the docs,

    "A contract class is a container for constants that define names for URIs, tables, and columns."

    only the schema of the database should be put in there. Logic pertaining to altering the database should be put inside the DBHelper class.