On Friday, April 26, 2013 11:20:20 AM UTC-5, Nathan wrote:
I can not figure out what is happening here for the life of me. Everything was working fine. I went to bed one night and came back the next and now my app will not read or write to my db and gives me no errors. Please help any advice would be great.--My DB Handler:============================================================ ============================== ===================== import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DatabaseHandler extends SQLiteOpenHelper {// All Static variables// Database Versionprivate static final int DATABASE_VERSION = 1;// Database Nameprivate static final String DATABASE_NAME = "GP";// Contacts table nameprivate static final String TABLE_VERSION = "GPVersion";// Contacts Table Columns namesprivate static final String KEY_ID = "id";private static final String KEY_VERSION = "name";public DatabaseHandler(Context context) {super(context, DATABASE_NAME, null, DATABASE_VERSION);}@Overridepublic void onCreate(SQLiteDatabase db) {// TODO Auto-generated method stubString CREATE_VERSION_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_VERSION + "("+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_VERSION + " TEXT" + ")";db.execSQL(CREATE_VERSION_TABLE); }@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {// TODO Auto-generated method stub//db.execSQL("DROP TABLE IF EXISTS " + TABLE_VERSION);// Create tables again//onCreate(db);}// Adding new versionvoid addGPVersion(String version) {SQLiteDatabase db = this.getWritableDatabase();ContentValues values = new ContentValues();values.put(KEY_ID, "0"); // Pairvalues.put(KEY_VERSION, version); // Pair// Inserting Rowdb.insert(TABLE_VERSION, null, values);db.close(); // Closing database connection}// Getting students Countpublic String getGPVersion() {SQLiteDatabase db = this.getReadableDatabase();String q="SELECT " + KEY_VERSION + " FROM " + TABLE_VERSION + " WHERE " + KEY_ID + "='0'";String z;Cursor cursor = db.rawQuery(q,null);if (cursor != null && cursor.getCount()>0) {cursor.moveToFirst();z=cursor.getString(0);cursor.close();db.close();return z;}else{cursor.close();db.close();return "na";}}============================================================ ============================== ===================== Main Activity:============================================================ ============================== ===================== @Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState); setContentView(R.layout.main);CheckGPVersion();}private void CheckGPVersion(){DatabaseHandler db = new DatabaseHandler(this);String a = "";a = db.getGPVersion();EditText txtEffortCode = (EditText) findViewById(R.id.txtEffortCode); txtEffortCode.setText(a);}public void onGoClick(View view) // Input Effort Code{EditText txtEffortCode = (EditText) findViewById(R.id.txtEffortCode); if (txtEffortCode.getText().length() != 0){ //Do SomethingDatabaseHandler db = new DatabaseHandler(this);db.addGPVersion(txtEffortCode.getText().toString(). toUpperCase(Locale.getDefault( ))); txtEffortCode.setText("");Toast.makeText(this, "Input Success!", Toast.LENGTH_SHORT).show();}else{//Alert no code inputToast.makeText(this, "You must enter 'EFFORT CODE'!", Toast.LENGTH_SHORT).show();}}============================================================ ============================== ===================== While it creates the database or so I think it does as the app shows under data 4.00K. When it was inputting data the other night, the data field showed 12.00K. Argh, what is going on here? I use sqlite on many other apps and they work fine. Did something get corrupt? I tried cleaning the project, rebooting etc. nothing. Thanks in advance.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups "Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment