Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLiteOpenHelper error

Tags:

android

sqlite

I read this http://developer.android.com/resources/tutorials/notepad/index.html and now try to create my own simple example. For simplification reasons I don't have my own Adapter Class. When I try this

SQLiteOpenHelper dbHelper = new SQLiteOpenHelper(this,"myDB.db3", null, 1);

in my applications onCreate method I see Ecplise telling me

Cannot instantiate the type SQLiteOpenHelper

I am not seeing what is basically different from the SDK tutorial (apart from that my call to the constructor is not wrapped in helper classes).

Thanks, A.

like image 265
AndyAndroid Avatar asked Mar 10 '11 12:03

AndyAndroid


People also ask

What is SQLiteOpenHelper?

android.database.sqlite.SQLiteOpenHelper. A helper class to manage database creation and version management.

Which of the following must be overridden while using SQLiteOpenHelper class?

SQLiteOpenHelper provides callback methods and we should override it to get our job done. Those callback methods that we can override are onCreate(), onUpgrade(), onOpen() and onDowngrade(). And onCreate() and onUpgrade() are abstract methods and must be overridden.

What is the use of onUpgrade function in SQLiteOpenHelper?

SQLiteOpenHelper is a helper class to manage database creation and version management. In this class, the onUpgrade() method is responsible for upgrading the database when you make changes to the schema.

What are the methods that must be implemented in a class that extends SQLiteOpenHelper explain them?

SQLiteOpenHelper class is used for database creation and version management. For performing any database operation, you have to provide the implementation of onCreate() and onUpgrade() methods of SQLiteOpenHelper class.


1 Answers

SQLiteOpenHelper is an abstract class, you should inherit from it in order to instantiate one.

public class MyOpenHelper extends SQLiteOpenHelper {

...

}

MyOpenHelper dbHelper = new MyOpenHelper(...);
like image 195
Vladimir Ivanov Avatar answered Sep 26 '22 06:09

Vladimir Ivanov