I tried using the source code posted but encounter the following error:
The method createDatabase(String, int, int, null) is undefined for the type Database
This error occurs at the following lines:
Using java Syntax Highlighting
- this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
- /* Open the DB and remember it */
- myDB = this.openDatabase(MY_DATABASE_NAME, null);
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
The method createDatabase(String, int, int, null) is undefined for the type Database
The entire source code is:
Using java Syntax Highlighting
- package com.android.Database;
- import java.io.FileNotFoundException;
- import java.util.ArrayList;
- import android.app.ListActivity;
- import android.database.Cursor;
- import android.database.sqlite.SQLiteDatabase;
- import android.os.Bundle;
- import android.widget.ArrayAdapter;
- import android.widget.EditText;
- public class Database extends ListActivity {
- private final String MY_DATABASE_NAME = "myCoolDB_2";
- private final String MY_DATABASE_TABLE = "Users";
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- EditText et = new EditText(this);
- et.setSelection(et.getText().length());
- /* Will hold the 'Output' we want to display at the end. */
- ArrayList<String> results = new ArrayList<String>();
- SQLiteDatabase myDB = null;
- try {
- /* Create the Database (no Errors if it already exists) */
- this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
- /* Open the DB and remember it */
- myDB = this.openDatabase(MY_DATABASE_NAME, null);
- /* Create a Table in the Database. */
- myDB.execSQL("CREATE TABLE IF NOT EXISTS "
- + MY_DATABASE_TABLE
- + " (LastName VARCHAR, FirstName VARCHAR,"
- + " Country VARCHAR, Age INT(3));");
- /* Add two DataSets to the Table. */
- myDB.execSQL("INSERT INTO "
- + MY_DATABASE_TABLE
- + " (LastName, FirstName, Country, Age)"
- + " VALUES ('Gramlich', 'Nicolas', 'Germany', 20);");
- myDB.execSQL("INSERT INTO "
- + MY_DATABASE_TABLE
- + " (LastName, FirstName, Country, Age)"
- + " VALUES ('Doe', 'John', 'US', 34);");
- /* Query for some results with Selection and Projection. */
- Cursor c = myDB.query("SELECT FirstName,Age" +
- " FROM " + MY_DATABASE_TABLE
- + " WHERE Age > 10 LIMIT 7;",
- null);
- /* Get the indices of the Columns we will need */
- int firstNameColumn = c.getColumnIndex("FirstName");
- int ageColumn = c.getColumnIndex("Age");
- /* Check if our result was valid. */
- if (c != null) {
- /* Check if at least one Result was returned. */
- if (c.first()) {
- int i = 0;
- /* Loop through all Results */
- do {
- i++;
- /* Retrieve the values of the Entry
- * the Cursor is pointing to. */
- String firstName = c.getString(firstNameColumn);
- int age = c.getInt(ageColumn);
- /* We can also receive the Name
- * of a Column by its Index.
- * Makes no sense, as we already
- * know the Name, but just to shwo we can <img src="http://www.anddev.org/images/smilies/wink.png" alt=";)" title="Wink" /> */
- String ageColumName = c.getColumnName(ageColumn);
- /* Add current Entry to results. */
- results.add("" + i + ": " + firstName
- + " (" + ageColumName + ": " + age + ")");
- } while (c.next());
- }
- }
- } catch (FileNotFoundException e) {
- } finally {
- if (myDB != null)
- myDB.close();
- }
- this.setListAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1_small, results));
- }
- }
Parsed in 0.042 seconds, using GeSHi 1.0.8.4
Please help!
Thanks





