I have been trying to work out the bug on this but can’t seem to find what I’m looking for search Google for the past few days, i have hit and missed on stuff that is leaning towards what i want to do but haven’t ran across anything that is what i am trying to do.
To start off, I built my SQLite DB along with “TheNewBoston Android Tuts” everything works fine, now that I am trying to change the view database around it errors out or crashes the app at start up. I am wanting to display certain columns in a row from the DB with the Cursor using the for loop and to dynamically load the TableView with the data:
DbEntry[ data | data| Displayed | data | Display | Display | data ]
I can do this if i have a TextView off on its own but with it in a TableLayout>TableRow i think that’s where the problem is but not sure… would like to be able to load the table rows from the class its self instead of setting the text views if possible. I hope i gave enough info on what i am trying to do, if anyone can point me to a really good tutorial or give some light on this, it wold be greatly appreciated.
XML:
<TableLayout
android:id="@+id/view_Table"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="4" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="@+id/view_DbCol3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DB Col 3 Displayed Data" />
</TableRow>
with xml i hope i am doing the table right that its similar to hmtl kind of things by putting table rows in side one another
SQLview Class
setContentView(R.layout.sqlview);
TextView tv = (TextView) findViewById(R.id.view_DbCol3);
try {
DBload info = new DBload(this);
info.open();
String data = info.getData();
info.close();
tv.setText(data);
} catch (Exception e) {
// Error Message Dialog
String error = e.getLocalizedMessage();
Dialog d = new Dialog(this);
d.setTitle("DB ERROR");
TextView tv1 = new TextView(this);
tv1.setText(error);
d.setContentView(tv1);
d.show();
}
DbHelper Class: getData Method
public String getData() {
String[] cols = new String[] {KEY_PLACE};
// I have also tried with all my KEY variables
// reads info from DB columns
Cursor c = ourDB.query(KEY_TABLE, cols, null, null, null, null, null);
String result = "";
int Ione = c.getColumnIndex(KEY_PLACE);
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result = result
+ c.getString(Ione)
+ "\n";
}
return result;
}
the error i am getting is
11-17 00:13:09.993: E/CursorWindow(590): Bad request for field slot 0,-1. numRows = 2, numColumns = 1
like i said i hope i have given enough information for little help if possible, thanks alot
This link will help you alot.
anywayz try this in you code
Hope this helps..