Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
Java Persistence with Spring Data and Hibernate
this week in the
Spring
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Android
Why it doesn't create data base table?
Serhii Stets
Greenhorn
Posts: 1
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Please help me!
this is my DB class
public class DBHelper extends SQLiteOpenHelper { public static final int DATABASE_VERSION = 1; public static final String DATABASE_NAME = "RemindDB"; public static final String TABLE_CONTACTS = "contacts"; public static final String KEY_ID = "_id"; public static final String KEY_DATE = "date"; public static final String KEY_HOUR = "hour"; public static final String KEY_MINUTE = "minute"; public static final String KEY_TODO = "todo"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table " + TABLE_CONTACTS + "(" + KEY_ID + " text primary key," + KEY_DATE + " text," + KEY_HOUR + " text," + KEY_MINUTE + " text," + KEY_TODO + " text" + ")"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("drop table if exists " + TABLE_CONTACTS); onCreate(db); } }
this is my main class
public void onClick(View v) { int id = v.getId(); String name = et_todo_name.getText().toString(); SQLiteDatabase database = dbHelper.getWritableDatabase(); ContentValues cv = new ContentValues(); if (id == R.id.btn_back1) { Intent intent = new Intent(AddingActivity.this, MainActivity.class); startActivity(intent); } else if (id == R.id.btn_add1) { cv.put(DBHelper.KEY_DATE, MainActivity.selectedDate); cv.put(DBHelper.KEY_HOUR, timePicker.getHour()); cv.put(DBHelper.KEY_MINUTE, timePicker.getMinute()); cv.put(DBHelper.KEY_TODO, name); database.insert(DBHelper.DATABASE_NAME, null, cv); } dbHelper.close(); } }
but value for data is null.
I am getting below error
07-09 10:09:48.463 19904-19904/devferrarizero.my_reminder E/SQLiteLog: (1) no such table: RemindDB 07-09 10:09:48.463 19904-19904/devferrarizero.my_reminder E/SQLiteDatabase: Error inserting date=09/09/2016 hour=0 todo=fdgbfd minute=5 android.database.sqlite.SQLiteException: no such table: RemindDB (code 1): , while compiling: INSERT INTO RemindDB(date,hour,todo,minute) VALUES (?,?,?,?) at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469) at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341) at devferrarizero.my_reminder.AddingActivity.onClick(AddingActivity.java:68) at android.view.View.performClick(View.java:5198) at android.view.View$PerformClick.run(View.java:21147) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Ron McLeod
Marshal
Posts: 4172
555
I like...
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
The log says "
no such table: RemindDB
". Are you trying to insert into the database (
RemindDB
) rather than the table (
contacts
)?
Brian Tkatch
Bartender
Posts: 598
26
I like...
posted 6 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
public static final String KEY_DATE = "date";
What Ron said. And, i was thinking that "date" is likely a keyword and might not be able to be used for a column (or any object) name.
Do not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Obtaining the arrayList from Sqlite database
Not able to Insert data in SQLite
How to get Id of a Particulat Record Insert in database
why it doesn't create data base table
why oncreate doesn't run always
More...