pintu
pintu

Reputation: 7

cannot resolve symbols 'SQLiteDatabase' in android studio

I've encountered a problem with Android Studio. When I create a database class file at that time, I get an error like, cannot resolve symbol'SQLiteDatabase'. I used Android Studio version 3.5.2 before doing the right thing, but after I update the system problem downloaded the same version again, since then the problem is coming into the database class file.

My database Class file

package com.example.demo;

import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBmain extends SQLiteOpenHelper {
    public DBmain(@Nullable Context context, @Nullable String name, @Nullable android.database.sqlite.**SQLiteDatabase**.CursorFactory factory, int version) {//**error cannot resolve symbole 'SQLiteDatabase'**
        super ( context, name, factory, version );
    }

    @Override
    public void onCreate(android.database.sqlite.**SQLiteDatabase** db) {//**error cannot resolve symbole 'SQLiteDatabase'**

    }

    @Override
    public void onUpgrade(android.database.sqlite.**SQLiteDatabase** db, int oldVersion, int newVersion) {//**error cannot resolve symbole 'SQLiteDatabase'**

    }
}

build Gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"
    defaultConfig {
        applicationId "com.example.demo"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

edit

package com.example.demo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBmain extends SQLiteOpenHelper {

    public DBmain(@Nullable Context context, @Nullable String name, @Nullable android.database.sqlite.SQLiteDatabase.CursorFactory factory, int version) {
        super ( context, name, factory, version );
    }

    @Override
    public void onCreate(android.database.sqlite.SQLiteDatabase sqLiteDatabase) {

    }

    @Override
    public void onUpgrade(android.database.sqlite.SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}

Upvotes: 0

Views: 1260

Answers (1)

forpas
forpas

Reputation: 164174

You must import SQLiteDatabase also:

import android.database.sqlite.SQLiteDatabase;

and then you can remove all android.database.sqlite. from the declarations of the SQLiteDatabase objects:

package com.example.demo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBmain extends SQLiteOpenHelper {
    public DBmain(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super ( context, name, factory, version );
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

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

    }
}

Upvotes: 1

Related Questions