I am getting error in execution of following as "Detached Thread"
*HomeAct.java*
package com.zensar.app;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class HomeAct extends Activity {
int ver = 1;
SQLiteDatabase db;
ListView list;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
loadDataToList();
}
private void loadDataToList() {
// TODO Auto-generated method stub
// DBhelper dbhelper;
// dbhelper = new DBhelper(this, "MyDb", null, ver);
db = dbhelper.getReadableDatabase();
String columns[] = new String[] {"name", "date","etype"};
Cursor cur = db.query("tbl_event", columns, null, null, null,
null,
"date");
if( cur == null )
{
Toast.makeText(context, "no rows found",
Toast.LENGTH_SHORT).show();
}
else {
ArrayList<String> arrlist = new ArrayList<String>();
for( int i = 1; i <= cur.getCount(); i++ ) {
cur.moveToNext();
String str = cur.getString(1) + " " +
cur.getInt(0);
arrlist.add(str);
}
ArrayAdapter<String> adapter = new
ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_single_choice, arrlist);
list.setAdapter(adapter);
}
cur.close();
}
private void init() {
// TODO Auto-generated method stub
DBhelper dbhelper= new DBhelper(this, "MyDb", null, ver);
SQLiteDatabase db = dbhelper.getWritableDatabase();
ContentValues val = new ContentValues();
val.put("SK", "10/2/90");
long num = db.insert("tb1_event",null, val);
Log.e("num", num+"");
db.close();
Toast.makeText(this, "Inserted row",
Toast.LENGTH_LONG).show();
}
}
*DBhelper.java*
package com.zensar.app;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.widget.Toast;
public class DBhelper extends SQLiteOpenHelper
{
Context context;
public DBhelper(Context context, String name, CursorFactory
factory,
int version) {
super(context, name, factory, version);
this.context=context;
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
final String CREATE_TABLE_EVENT_INFO =
"CREATE TABLE tbl_event ("
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "name TEXT NOT NULL,"
+ "date DATE NOT NULL,"
+ "etype TEXT);";
final String CREATE_TABLE_EMAIL_INFO =
"CREATE TABLE tb2_email ("
+ "id INTEGER REFERENCES tb1_event(id),"
+ "email TEXT NOT NULL);";
db.execSQL(CREATE_TABLE_EVENT_INFO);
db.execSQL(CREATE_TABLE_EMAIL_INFO);
Toast.makeText( context , "created...",
Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion)
{
// TODO Auto-generated method stub
Toast.makeText( context, "upgraded..." + oldVersion +" " +
newVersion, Toast.LENGTH_SHORT).show();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en