It works with Android SQLite, but it doesn't run during Run.

Asked 2 years ago, Updated 2 years ago, 34 views

---------- error log portion. I've copied and pasted only the suspected cause ---------

FATAL EXCEPTION: main Process: com.example.karry.autocompleted, PID: 1707 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.karry.autocompleted/com.example.karry.autocompleted.SQLiteAssistant}: java.lang.InstantiationException: java.lang.Class has no zero argument constructor

Caused by: java.lang.InstantiationException: java.lang.Class has no zero argument constructor at java.lang.Class.newInstance(Native Method)

----------------- Below is the source code part for the class that is failing -------------------

public class SQLiteAssistant extends SQLiteOpenHelper
{

private static final String DB_NAME = "usingsqlite.db";
private static final int DB_VERSION_NUMBER = 1;
private static final String DB_TABLE_NAME = "Datas";
private static final String DB_COLUMN_1_NAME = "Data Name";

private static final String DB_CREATE_SCRIPT = "create table " + DB_TABLE_NAME;

private SQLiteDatabase sqliteDBInstance = null;


 public SQLiteAssistant(Context context)
{
    super(context, DB_NAME, null, DB_VERSION_NUMBER);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{

}

public void onCreate(SQLiteDatabase sqliteDBInstance)
{
//      //      Log.i("onCreate", "Creating the database...");
    sqliteDBInstance.execSQL(DB_CREATE_SCRIPT);
}

public void openDB() throws SQLException
{
//      //      Log.i("openDB", "Checking sqliteDBInstance...");
    if(this.sqliteDBInstance == null)
    {
        Log.i("openDB", "Creating sqliteDBInstacne...");
        this.sqliteDBInstance = this.getWritableDatabase();
    }
}

public void closeDB()
{
    if(this.sqliteDBInstance != null)
    {
        if(this.sqliteDBInstance.isOpen())
            this.sqliteDBInstance.close();
    }
}

public long insertData(String DataName)
{
    ContentValues contentValues = new ContentValues();
    contentValues.put(DB_COLUMN_1_NAME, DataName);
    Log.i(this.toString() + " - insertData", "Inserting : " + DataName);
    return this.sqliteDBInstance.insert(DB_TABLE_NAME, null, contentValues);
}

public boolean removeCountry(String DataName)
{
    int result = this.sqliteDBInstance.delete(DB_TABLE_NAME, "Data Name = " + DataName + "'", null);

    if(result > 0)
        return true;
    else
        return false;
}

public long updateData(String oldDataName, String newDataName)
{
    ContentValues contentValues = new ContentValues();
    contentValues.put(DB_COLUMN_1_NAME, newDataName);
    return this.sqliteDBInstance.update(DB_TABLE_NAME, contentValues, "Data Name = " + oldDataName + "", null);
}

public String[] getAlldata()
{
    Cursor cursor = this.sqliteDBInstance.query(DB_TABLE_NAME, new String[]
            {
                    DB_COLUMN_1_NAME
            },
            null,null,null,null,null);

    if(cursor.getCount() > 0)
    {
        String[] str = new String[cursor.getCount()];
        int i = 0;

        while(cursor.moveToNext())
        {
            str[i] = cursor.getString(cursor.getColumnIndex(DB_COLUMN_1_NAME));
            i++;
        }
        return str;
    }
    else
    {
        return new String[]
                {

                };
    }
}

}

What could be the cause? If I read the error with my skills, it seems that it appears that there is no ctor without parameters, but the same error occurs even if you make such a ctor.ㅠ<

It's a symptom that connects to Android and goes back to Run, but it turns off as if something is on and off on Android, and I stopped the app_name in the message. That's what it says. In the log of Android studio, the error I attached above is printed out.

android sql

2022-09-21 18:57

1 Answers

The SQLite Assistant code you uploaded seems to be fine. Make sure you have set up the running activity properly in AndroidManifest.xml.


2022-09-21 18:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.