Alright I have been working on a chess clock of epic proportions and almost have it up and running. But for the last and coolest part of its functionality I have hit a wall and would appreciate some help.
The story so far: The DatabaseHelper class can successfully add rows to the data base which happens in an activity called add precept. I have pulled the db file off the device and viewed it with SQLite viewer and all is well. When I try to load one of the rows and use the data for the main activities state things begin to go astray. I have a method in the main activity called setClocks its a wrapper class that uses the DatabaseHelper method getEntry to fill a MyObject which has all the data I need to set the apps state. Please help me figure out why a call of setClocks(1); results in an exception no row found. Here is the code: [code] //The wrapper class in the main activity public void setClocks(long index) { MyObject data; dbh.open(); data = dbh.getEntry(index); if( data.handiState == "white" ) { ctBlack.SetTime(data.timeInMills); ctWhite.SetTime(data.timeInMills + data.handiTimeInMills); } else if( data.handiState == "black" ) { ctWhite.SetTime(data.timeInMills); ctBlack.SetTime(data.timeInMills + data.handiTimeInMills); } else if ( data.handiState == "none" ) { ctBlack.SetTime(data.timeInMills); ctWhite.SetTime(data.timeInMills); } isFisher = Boolean.parseBoolean(data.isFisher); fisherTimeInMills = data.fisherTimeInMills; dbh.close(); } //The DatabaseHelper method public MyObject getEntry(long _rowIndex) throws SQLException { Cursor cursor = db.query(true, DATABASE_TABLE, null, KEY_ID + "=" + _rowIndex, null, null, null, null, null); if ((cursor.getCount() == 0) || !cursor.moveToFirst()) { throw new SQLException("No to do item found for row: " + _rowIndex); } MyObject entry = new MyObject(); entry.name = cursor.getString(cursor.getColumnIndex(KEY_NAME)); entry.timeInMills = cursor.getLong(cursor.getColumnIndex(KEY_TIM)); entry.handiTimeInMills = cursor.getLong(cursor.getColumnIndex(KEY_HTIM)); entry.fisherTimeInMills = cursor.getLong(cursor.getColumnIndex(KEY_FTIM)); entry.handiState = cursor.getString(cursor.getColumnIndex(KEY_HCS)); entry.isFisher = cursor.getString(cursor.getColumnIndex(KEY_IF)); return entry; } //Definition of my object public class MyObject { public String name; public long timeInMills; public long fisherTimeInMills; public long handiTimeInMills; public String isFisher; public String handiState; } [/code] If I call setClocks(1); in the onCreate of the main activity the app crashes with the could not find row exception. I know their is a row with an _id of 1 I can see it on my desktop. I want to load the first precet when the app loads and then in the onCreateOptionsMenu I have an option to select a preset. When this is selected it displays a dialog with a spinner and 2 buttons one for loading the selected preset and one for removing the selected preset from the database. Here is my attempt at that. It loads the dialog and the dialog is populated by the database but when I press load it just goes back to the main activity with the timers as they where. [code] public boolean onOptionsItemSelected(MenuItem item) { switch( item.getItemId() ) { case R.id.Menu_LoadPreff: final Dialog dialog = new Dialog(this); dialog.setTitle("Pick a precet"); dialog.setCancelable(true); dialog.setContentView(R.layout.precetselector); final Spinner spinner = (Spinner) dialog.findViewById(R.id.SpinPrecet); dbh.open(); Cursor select = dbh.getAllEntries(); SimpleCursorAdapter myAdapt = new SimpleCursorAdapter(dialog.getContext(), android.R.layout.two_line_list_item, select, new String[] {DatabaseHelper.KEY_NAME, DatabaseHelper.KEY_ID,}, new int[] {android.R.id.text1}); spinner.setAdapter(myAdapt); dialog.show(); Button load, delete; load = (Button) dialog.findViewById(R.id.PrecetLoad); delete = (Button) dialog.findViewById(R.id.PrecetDelete); load.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { setClocks(spinner.getSelectedItemPosition()+1); dialog.dismiss(); dbh.close(); } }); break; [/code] And if you need it the setTime method for a ChessClock an inner class of the main Activity which has its own inner class CountDownTimer [code] public void SetTime(long millisInFuture) { timer = new Timer( millisInFuture, 1000); //Timer is the inner CountDownTimer tv.setText(formatTime(millisInFuture)); //tv is the linked text view length = millisInFuture; //length is used for the reset button or when one player looses and the activity starts over } [/code] Thank you for reading hope all is well. -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en