Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 73: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 74: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 75: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 76: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 77: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /bbc_download.php on line 78: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
package com.allergycookbook; import java.io.IOException; import android.app.ListActivity; import android.database.Cursor; import android.database.SQLException; import android.os.Bundle; import android.widget.SimpleCursorAdapter; import android.widget.Toast; public class AllergyCookBook extends ListActivity { /** Called when the activity is first created. */ //@Override private DataBaseHelper myDbHelper; private Cursor mNotesCursor; private static final String DATABASE_TABLE = "recipes"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //set to main if there's problems setContentView(R.layout.recipe_list); DataBaseHelper myDbHelper = new DataBaseHelper(getBaseContext()); myDbHelper = new DataBaseHelper(getBaseContext()); try { myDbHelper.createDataBase(); Toast.makeText(AllergyCookBook.this, "Database creation success", Toast.LENGTH_SHORT).show(); } catch (IOException ioe) { throw new Error("Unable to create database"); } // Get all of the rows from the database and create the item list myDbHelper.openDataBase(); fillData(); registerForContextMenu(getListView()); } //comment out everything below and it works private void fillData() { //the problem is definitely here // Get all of the rows from the database and create the item list mNotesCursor = myDbHelper.fetchAllNotes(); startManagingCursor(mNotesCursor); // Create an array to specify the fields we want to display in the list (only TITLE) String[] from = new String[]{DataBaseHelper.KEY_TITLE}; // and an array of the fields we want to bind those fields to (in this case just text1) int[] to = new int[]{R.id.text1}; // Now create a simple cursor adapter and set it to display SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.recipe_row, mNotesCursor, from, to); setListAdapter(notes); } /////////////////////////////////////////////////////////////////////////////////////////// package com.allergycookbook; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; public class DataBaseHelper extends SQLiteOpenHelper{ //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.allergycookbook/databases/"; private static String DB_NAME = "cookbook"; public static final String KEY_TITLE = "recipe_name"; public static final String KEY_ROWID = "_id"; private static final String DATABASE_TABLE = "recipes"; private SQLiteDatabase myDataBase; private final Context myContext; // /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @param context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own database. * */ public void createDataBase() throws IOException{ // create new //this.getReadableDatabase(); /*myDataBase.execSQL("CREATE TABLE IF NOT EXISTS " + DATABASE_TABLE + " (_id INTEGER PRIMARY KEY, recipe_name TEXT," + " ingredients TEXT, method TEXT);");*/ boolean dbExist = checkDataBase(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we are gonna be able to overwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ /*myDataBase.execSQL("CREATE TABLE IF NOT EXISTS " + DATABASE_TABLE + " (_id INTEGER PRIMARY KEY, recipe_name TEXT," + " ingredients TEXT, method TEXT);"); ContentValues values = new ContentValues(); values.put("recipe_name", "pancakes"); //values.put("field2", "value_for_field2"); myDataBase.insert(DATABASE_TABLE, null, values);*/ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open("cookbook"); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); //Toast.makeText(DataBaseHelper.this, "Database copying success", Toast.LENGTH_SHORT).show(); } public void openDataBase() throws SQLException{ //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Override public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Override public void onCreate(SQLiteDatabase db) { } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. //start of my additions public Cursor fetchAllNotes(){ try{ return myDataBase.query(DATABASE_TABLE, new String[] {"_id", "recipe_name"}, null, null, null, null,null); }catch(SQLiteException e){ return null; //database does't exist yet. } //return myDataBase.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE},null,null,null,null,null); } /** * Return a Cursor positioned at the note that matches the given rowId * * @param rowId id of note to retrieve * @return Cursor positioned to matching note, if found * @throws SQLException if note could not be found/retrieved */ public Cursor fetchNote(long rowId) throws SQLException { Cursor mCursor = myDataBase.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE}, KEY_ROWID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } //end of my additions } }