-2

I am coding an app for my assignment using Android Studio where the user can add a customer to the database. However, the line getWritableDatabase(); shows the problem that is in the title.

String id,name,address,number,email,jobs; is what I'm assuming I need to adjust.

@Override
protected String doInBackground(String... params) {

    String method = params[0];
    DatabaseHelper databaseHelper = new DatabaseHelper(context);

    if(method.equals("add_info"))
    {
        String id = params[1];
        String Name = params[2];
        String Address = params[3];
        int Number = Integer.parseInt(params[4]);
        String Email = params[5];
        String Jobs = params[5];
        SQLiteDatabase database = DatabaseHelper.getWritableDatabase();
        DatabaseHelper.addInformations(database,id, Name, Address, Email, Jobs);
        return "Information Inserted.....";

    }
    return null;
}
Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
  • @Override protected String doInBackground(String... params) { String method = params[0]; DatabaseHelper databaseHelper = new DatabaseHelper(context); This is the top part of the code before the if – Michael Phillips May 21 '19 at 23:23

1 Answers1

0

DatabaseHelper.getWritableDatabase() means that you're calling a class method that has no particular object associated with the call. This is basically a function call rather than a method call, as a method call is associated with a particular instance of an object.

From what you show, the getWritableDatabase() function is actually not a class method but an instance method. That means it is supposed to be called on an instance of DatabaseHelper. That you aren't calling it via an instance of DatabaseHelper is what's giving you this error. The way you want to use this method is:

<instance of DatabaseHelper>.getWriteableDatabase()

You've got such an object right there in your code, via the line:

DatabaseHelper databaseHelper = new DatabaseHelper(context);

so it seems that what you mean to be doing is this:

SQLiteDatabase database = databaseHelper.getWriteableDatabase()

the same is likely true for the following line, which should be:

databaseHelper.addInformations(database,id, Name, Address, Email, Jobs);

You should use identifiers with lowercase first letters for variable names and reserve identifiers with uppercase first letters for the names of classes and other types. This is the standard Python way, although obviously, the Python language itself does not enforce this. Not doing this is, I expect, a major contributor to the slight mistake that you made. So: name, address, number, email...

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
  • Hey, thanks for the help. I've managed to fix that. but "DatabaseHelper.addInformations(database,id, Name, Address, Email, Jobs);" has a problem. ".addInformations" has a popup error which is "Cannot resolve method 'addInformations(android.database.sqlite.SQLiteDatabase, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String". Any ideas? – Michael Phillips May 22 '19 at 09:44
  • databaseHelper.addInformation(SQLiteDatabase database, id, Name, Address, Email, Jobs); is what I've done so far, but between SQLiteDatabase database either "," or ")" is expected, but neitherworks – Michael Phillips May 22 '19 at 10:11