created class TestDataBaseHelper extends SQLiteOpenHelper . In the MainActivity in the onCreate() method, an attempt is made to create an object of this class, but Android Studio swears that it does not see this class and offers to create it. why it happens? Here is a piece of code from the TestDataBaseHelper class:

 public class TestDataBaseHelper extends SQLiteOpenHelper { private static final int DB_VERSION = 1; private static final String DB_NAME = "test.db"; TestDataBaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE TEST (_id INTEGER PRIMARY KEY AUTOINCREMENT,"+"NAME TEXT);"); insertTest(db,"Alexandr"); insertTest(db,"Peter"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { onCreate(db); } private static void insertTest(SQLiteDatabase db, String name){ ContentValues testValues = new ContentValues(); testValues.put("NAME", name); db.insert("TEST", null, testValues); } } 

piece of code MainActivity :

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SQLiteOpenHelper testDataBaseHelper = new TestDataBaseHelper(this); SQLiteDatabase db = testDataBaseHelper.getWritableDatabase(); } 
  • If the classes are in different packages, add the public modifier to the class constructor. - Arentheal

1 answer 1

Most likely you have the TestDataBaseHelper class stored in a different package. add a modifier to your constructor.

  public TestDataBaseHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); }