FIrst of all i'm fairly new to Android and have been playing around for some days now. I have followed the Notepad tutorial from NotepadV1 to NotepadV3. After completing this tutorial i've been customizing the application with differents of api's, but i got stuck when i made a database connection in MyView class. Without the database connection it works perfectly. But then the count isn't dynamic. The application is actually still the same but instead of a list i wanted to show images.
the dbAdapter class is still the same as NotesDbAdapter. I just renamed it.
MyView
Using java Syntax Highlighting
- public class MyView extends View {
- private Drawable icon;
- private Cursor cursor;
- private DBAdapter dbAdapter;
- public MyView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- loadTree(context);
- }
- public MyView(Context context, AttributeSet attrs) {
- super(context, attrs);
- loadTree(context);
- }
- public MyView(Context context) {
- super(context);
- loadTree(context);
- }
- public void loadTree(Context context) {
- icon = context.getResources().getDrawable(R.drawable.icon);
- dbAdapter = new DBAdapter(context);
- dbAdapter.open();
- setFocusable(true);
- }
- @Override
- protected void onDraw(Canvas canvas) {
- super.onDraw(canvas);
- int count = dbAdapter.fetchAllNotes().getCount();
- int i = 0;
- while(i<count) {
- icon.setBounds(15+i, 15+i, 15+i + 15+i, 15+i + 15+i);
- icon.draw(canvas);
- i = i++;
- }
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- return super.onTouchEvent(event);
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
The error im getting is:
sqlexception no such table: notes
But i dont understand this, because i did:
dbAdapter = new DBAdapter(context);
dbAdapter.open();
it should be created and opened and if it does not exist it will be created, the flow is also good i debuged it in eclipse with some breakpoints.
If this can't be helped because of the structure the Notepad is, can someone give me a good practice of retrieving data from the databse from out a view class?


