Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy my data is not shown?
    primarykey
    data
    text
    <p>I am trying to retrieve data from a db. I don't get any error, but the data is not shown. Here is my code:</p> <p>DbHelper</p> <pre><code>public class DbHelper extends SQLiteOpenHelper{ static final String tag="dbHelper"; static final String DB_NAME="dianaaaa.db"; static final int DB_VERSION=1; static final String TABLE_JOBS="jobs"; static final String C_START="start"; static final String C_STOP="stop"; static final String C_ID_J=BaseColumns._ID; Context context; SQLiteDatabase db; public DbHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); // TODO Auto-generated constructor stub this.context=context; } @Override public void onCreate(SQLiteDatabase db) { String sql2="create table "+TABLE_JOBS+"( "+C_ID_J+" INTEGER PRIMARY KEY, "+C_START+" text, "+C_STOP+" text)"; try{ db.execSQL(sql2); } catch(SQLException e){ Log.d(tag, "no"); }finally{ } } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("drop table if exists "+TABLE_JOBS); Log.d(tag, "onUpdated"); onCreate(db); } public void insertJStart(String s1){ SQLiteDatabase db = (SQLiteDatabase) getWritableDatabase(); ContentValues values=new ContentValues(); values.clear(); values.put(DbHelper.C_START, s1); try{ db.insertOrThrow(TABLE_JOBS, C_START, values); }catch(SQLException e){ Log.d(tag, "nu vreau...."); }finally{ db.close(); } } public void insertJStop(String s2){ SQLiteDatabase db=(SQLiteDatabase) getWritableDatabase(); ContentValues values=new ContentValues(); values.clear(); values.put(DbHelper.C_STOP, s2); db.insertOrThrow(TABLE_JOBS, C_STOP, values); db.close(); } public Cursor getCursor(){ SQLiteQueryBuilder queryBuilder=new SQLiteQueryBuilder(); queryBuilder.setTables(TABLE_JOBS); String[] asColumToRetrun=new String[] { C_ID, C_START, C_STOP}; Cursor mCursor=db.query(TABLE_JOBS, asColumToRetrun, null, null, null, null, "time ASC"); return mCursor; } public String getDate(Cursor c, int i){ return (c.getString(i)); } public Cursor getAll(){ db=this.getReadableDatabase(); Cursor c=db.rawQuery("SELECT * FROM jobs ", new String[]{}); return c; } } </code></pre> <p>Activity:</p> <pre><code>public class TimerDB extends Activity{ static final String tag="TimerDB"; private ListView list; MyAdapter aa=null; private Cursor cursor=null; private DbHelper helper=null; final ArrayList&lt;String&gt; aList=new ArrayList&lt;String&gt;(); @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.times); list=(ListView)findViewById(R.id.timeList); helper=new DbHelper(this); cursor=helper.getAll(); cursor.moveToNext(); startManagingCursor(cursor); aa=new MyAdapter(cursor); list.setAdapter(aa); } class MyAdapter extends CursorAdapter{ MyAdapter(Cursor c){ super(TimerDB.this, c); } public View getView(int position, View convertView, ViewGroup parent){ View row=convertView; if(row==null){ LayoutInflater inflater=getLayoutInflater(); row=inflater.inflate(R.layout.row, null); } return (row); } @Override public void bindView(View row, Context context, Cursor c) { // TODO Auto-generated method stub Holder holder=(Holder) row.getTag(); holder.populateFrom(c, helper); c.moveToNext(); } @Override public View newView(Context context, Cursor c, ViewGroup parent) { // TODO Auto-generated method stub LayoutInflater inflater=getLayoutInflater(); View row=inflater.inflate(R.layout.row, parent, false); Holder holder=new Holder(row); row.setTag(holder); return row; } } static class Holder { private TextView id, start, stop; Holder(View row){ id=(TextView) row.findViewById(R.id.rowViewStart); start=(TextView) row.findViewById(R.id.rowViewStart); stop=(TextView) row.findViewById(R.id.rowViewStop); } void populateFrom(Cursor c, DbHelper db){ id.setText(db.getDate(c, 0)); start.setText(db.getDate(c, 1)); stop.setText(db.getDate(c, 2)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload