Cannot resolve method super in attempt to make SQL lite database (Android Studio Beginner issue)
I'm a beginner in android Studio, I am following a tutorial with code like this
public class dbhelper extends SQLiteOpenHelper {
public static final string DATABASE_NAME = "perpustakaan.db";
public static final string TABLE_NAME = "user";
public static final string DATABASE_VERSION = 1;
public static final string COL_1 = "username";
public static final string COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
On the line super the android studio said it was an error, while I saw the tutorial it didn't call an error. I'm using the Android Studio ver 3.2.1
sqlite android-studio
add a comment |
I'm a beginner in android Studio, I am following a tutorial with code like this
public class dbhelper extends SQLiteOpenHelper {
public static final string DATABASE_NAME = "perpustakaan.db";
public static final string TABLE_NAME = "user";
public static final string DATABASE_VERSION = 1;
public static final string COL_1 = "username";
public static final string COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
On the line super the android studio said it was an error, while I saw the tutorial it didn't call an error. I'm using the Android Studio ver 3.2.1
sqlite android-studio
add a comment |
I'm a beginner in android Studio, I am following a tutorial with code like this
public class dbhelper extends SQLiteOpenHelper {
public static final string DATABASE_NAME = "perpustakaan.db";
public static final string TABLE_NAME = "user";
public static final string DATABASE_VERSION = 1;
public static final string COL_1 = "username";
public static final string COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
On the line super the android studio said it was an error, while I saw the tutorial it didn't call an error. I'm using the Android Studio ver 3.2.1
sqlite android-studio
I'm a beginner in android Studio, I am following a tutorial with code like this
public class dbhelper extends SQLiteOpenHelper {
public static final string DATABASE_NAME = "perpustakaan.db";
public static final string TABLE_NAME = "user";
public static final string DATABASE_VERSION = 1;
public static final string COL_1 = "username";
public static final string COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
On the line super the android studio said it was an error, while I saw the tutorial it didn't call an error. I'm using the Android Studio ver 3.2.1
sqlite android-studio
sqlite android-studio
asked Nov 15 '18 at 18:43
Kevin EdgarKevin Edgar
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
- You have mismatched braces (last one is missing)
- string should be String (upper case S).
- You cannot assign a numeric value to a String DATABASE_VERSION needs to be an int (lowercase).
- int is a primitive type (as are short, long, char, byte, boolean, float, double) and are lower case, String is a Class and by convention starts with an Uppercase (Pascal case),
- if you were to follow such Conventions instead of dbhelper you would use DBHelper rather than dbhelper.
- You need to add two overidden methods for onCreate and onUpgrade as these are required.
So the above at a minimum needs to be something like :-
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "perpustakaan.db";
public static final String TABLE_NAME = "user";
public static final int DATABASE_VERSION = 1;
public static final String COL_1 = "username";
public static final String COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
}
}
- Note that DATABASE_VERSION has been used for the database version (otherwsie it is useless).
In the onCreate method you would typically define the table(s) that are to be in the database.
Perhaps the onCreate method could be :-
@Override
public void onCreate(SQLiteDatabase db) {
String crt_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(" +
COL_1 + " TEXT UNIQUE," +
COL_2 + " TEXT" +
")";
db.execSQL(crt_sql);
}
Thus, when the onCreate method is called the user table would be created.
- The onCreate method is called once only for the lifetime of the database.
- The onCreate method is not called when you instantiate the dbhelper class (e.g. by using
dbhelper mydatabase = new dbhelper(this);
but when an attempt is made to accesss the database)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326011%2fcannot-resolve-method-super-in-attempt-to-make-sql-lite-database-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- You have mismatched braces (last one is missing)
- string should be String (upper case S).
- You cannot assign a numeric value to a String DATABASE_VERSION needs to be an int (lowercase).
- int is a primitive type (as are short, long, char, byte, boolean, float, double) and are lower case, String is a Class and by convention starts with an Uppercase (Pascal case),
- if you were to follow such Conventions instead of dbhelper you would use DBHelper rather than dbhelper.
- You need to add two overidden methods for onCreate and onUpgrade as these are required.
So the above at a minimum needs to be something like :-
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "perpustakaan.db";
public static final String TABLE_NAME = "user";
public static final int DATABASE_VERSION = 1;
public static final String COL_1 = "username";
public static final String COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
}
}
- Note that DATABASE_VERSION has been used for the database version (otherwsie it is useless).
In the onCreate method you would typically define the table(s) that are to be in the database.
Perhaps the onCreate method could be :-
@Override
public void onCreate(SQLiteDatabase db) {
String crt_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(" +
COL_1 + " TEXT UNIQUE," +
COL_2 + " TEXT" +
")";
db.execSQL(crt_sql);
}
Thus, when the onCreate method is called the user table would be created.
- The onCreate method is called once only for the lifetime of the database.
- The onCreate method is not called when you instantiate the dbhelper class (e.g. by using
dbhelper mydatabase = new dbhelper(this);
but when an attempt is made to accesss the database)
add a comment |
- You have mismatched braces (last one is missing)
- string should be String (upper case S).
- You cannot assign a numeric value to a String DATABASE_VERSION needs to be an int (lowercase).
- int is a primitive type (as are short, long, char, byte, boolean, float, double) and are lower case, String is a Class and by convention starts with an Uppercase (Pascal case),
- if you were to follow such Conventions instead of dbhelper you would use DBHelper rather than dbhelper.
- You need to add two overidden methods for onCreate and onUpgrade as these are required.
So the above at a minimum needs to be something like :-
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "perpustakaan.db";
public static final String TABLE_NAME = "user";
public static final int DATABASE_VERSION = 1;
public static final String COL_1 = "username";
public static final String COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
}
}
- Note that DATABASE_VERSION has been used for the database version (otherwsie it is useless).
In the onCreate method you would typically define the table(s) that are to be in the database.
Perhaps the onCreate method could be :-
@Override
public void onCreate(SQLiteDatabase db) {
String crt_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(" +
COL_1 + " TEXT UNIQUE," +
COL_2 + " TEXT" +
")";
db.execSQL(crt_sql);
}
Thus, when the onCreate method is called the user table would be created.
- The onCreate method is called once only for the lifetime of the database.
- The onCreate method is not called when you instantiate the dbhelper class (e.g. by using
dbhelper mydatabase = new dbhelper(this);
but when an attempt is made to accesss the database)
add a comment |
- You have mismatched braces (last one is missing)
- string should be String (upper case S).
- You cannot assign a numeric value to a String DATABASE_VERSION needs to be an int (lowercase).
- int is a primitive type (as are short, long, char, byte, boolean, float, double) and are lower case, String is a Class and by convention starts with an Uppercase (Pascal case),
- if you were to follow such Conventions instead of dbhelper you would use DBHelper rather than dbhelper.
- You need to add two overidden methods for onCreate and onUpgrade as these are required.
So the above at a minimum needs to be something like :-
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "perpustakaan.db";
public static final String TABLE_NAME = "user";
public static final int DATABASE_VERSION = 1;
public static final String COL_1 = "username";
public static final String COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
}
}
- Note that DATABASE_VERSION has been used for the database version (otherwsie it is useless).
In the onCreate method you would typically define the table(s) that are to be in the database.
Perhaps the onCreate method could be :-
@Override
public void onCreate(SQLiteDatabase db) {
String crt_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(" +
COL_1 + " TEXT UNIQUE," +
COL_2 + " TEXT" +
")";
db.execSQL(crt_sql);
}
Thus, when the onCreate method is called the user table would be created.
- The onCreate method is called once only for the lifetime of the database.
- The onCreate method is not called when you instantiate the dbhelper class (e.g. by using
dbhelper mydatabase = new dbhelper(this);
but when an attempt is made to accesss the database)
- You have mismatched braces (last one is missing)
- string should be String (upper case S).
- You cannot assign a numeric value to a String DATABASE_VERSION needs to be an int (lowercase).
- int is a primitive type (as are short, long, char, byte, boolean, float, double) and are lower case, String is a Class and by convention starts with an Uppercase (Pascal case),
- if you were to follow such Conventions instead of dbhelper you would use DBHelper rather than dbhelper.
- You need to add two overidden methods for onCreate and onUpgrade as these are required.
So the above at a minimum needs to be something like :-
public class dbhelper extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "perpustakaan.db";
public static final String TABLE_NAME = "user";
public static final int DATABASE_VERSION = 1;
public static final String COL_1 = "username";
public static final String COL_2 = "password";
public dbhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
}
}
- Note that DATABASE_VERSION has been used for the database version (otherwsie it is useless).
In the onCreate method you would typically define the table(s) that are to be in the database.
Perhaps the onCreate method could be :-
@Override
public void onCreate(SQLiteDatabase db) {
String crt_sql = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + "(" +
COL_1 + " TEXT UNIQUE," +
COL_2 + " TEXT" +
")";
db.execSQL(crt_sql);
}
Thus, when the onCreate method is called the user table would be created.
- The onCreate method is called once only for the lifetime of the database.
- The onCreate method is not called when you instantiate the dbhelper class (e.g. by using
dbhelper mydatabase = new dbhelper(this);
but when an attempt is made to accesss the database)
answered Nov 15 '18 at 19:34
MikeTMikeT
17.4k112743
17.4k112743
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326011%2fcannot-resolve-method-super-in-attempt-to-make-sql-lite-database-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown