views:

43

answers:

0

public class List2 extends ListActivity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get a cursor with all people
    Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null);
    startManagingCursor(c);

    ListAdapter adapter = new SimpleCursorAdapter(this, 
            // Use a template that displays a text view
            android.R.layout.simple_list_item_1, 
            // Give the cursor to the list adatper
            c, 
            // Map the NAME column in the people database to...
            new String[] {People.NAME} ,
            // The "text1" view defined in the XML template
            new int[] {android.R.id.text1}); 
    setListAdapter(adapter);
}

}

If I want to place my own database and columns, i have to replace the People.CONTENT_URI. But ive already replaced it but there's still a force close for my application. How can I solve this problem?

This is my DBAdapter.java

public class DBAdapter {
//values for the login table public static final String KEY_ROWID = "_id"; public static final String KEY_USER = "user"; public static final String KEY_PASSWORD = "pass"; public static final String KEY_NUMBER ="no"; public static final String KEY_STATUS="status";

//Values for the entry table
public static final String KEY_ROWID2 = "_id2";
public static final String KEY_TITLE = "title";
public static final String KEY_ENTRY = "entry";
public static final String KEY_DATE = "date";
public static final String KEY_TIME = "time";

private static final String TAG = "DBAdapter";

//declare Database name, tables names
private static final String DATABASE_NAME = "789";
private static final String DATABASE_TABLE = "Login";
private static final String DATABASE_TABLE_2 = "Entry";
private static final int DATABASE_VERSION = 1;

//declares the rules for the database tables
private static final String DATABASE_CREATE =
    "create table login (_id integer primary key autoincrement, "
    + "user text not null, pass text not null," 
    + " no integer not null, status text not null);";

private static final String DATABASE_CREATE_2 =
    "create table entry (_id2 integer primary key autoincrement, "
    + "title text,entry text, mood text, date text not null, "
    + "time text not null);";

public static final Uri CONTENT_URI = null;

private final Context context; 

private DatabaseHelper DBHelper;
private SQLiteDatabase db;

public DBAdapter(Context ctx) 
{
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}

private static class DatabaseHelper extends SQLiteOpenHelper 
{
    DatabaseHelper(Context context) 
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    //Create the tables with the rules we set.
    @Override
    public void onCreate(SQLiteDatabase db) 
    {
        db.execSQL(DATABASE_CREATE);
        db.execSQL(DATABASE_CREATE_2);
    }

    //OnUpgrade is only for use when u changed the database's version to 2 etc.
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, 
    int newVersion) 
    {
        Log.w(TAG, "Upgrading database from version " + oldVersion 
                + " to "
                + newVersion + ", which will destroy all old data");
        db.execSQL("DROP TABLE IF EXISTS titles");
        onCreate(db);
    }
}    

//---opens the database---
public DBAdapter open() throws SQLException 
{
    db = DBHelper.getWritableDatabase();
    return this;
}

//---closes the database---    
public void close() 
{
    DBHelper.close();
}

//Method for inserting login details, can be used in other java files when DBAdapter is
//declared in the java file. e.g. DBAdapter db = new DBAdapter(this);
public long insertLogin(String user, String pass, String no, String status) 
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_USER, user);
    initialValues.put(KEY_PASSWORD, pass);
    initialValues.put(KEY_NUMBER, no);
    initialValues.put(KEY_STATUS, status);
    return db.insert(DATABASE_TABLE, null, initialValues);
}


public long insertEntry(String title, String entry, String date, String time) 
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_TITLE, title);
    initialValues.put(KEY_ENTRY, entry);
    initialValues.put(KEY_DATE, date);
    initialValues.put(KEY_TIME, time);
    return db.insert(DATABASE_TABLE_2, null, initialValues);
}

//---deletes a particular title---
public boolean deleteLogin(long rowId) 
{
    return db.delete(DATABASE_TABLE, KEY_ROWID + 
      "=" + rowId, null) > 0;
}

public boolean deleteEntry(long rowId2) 
{
    return db.delete(DATABASE_TABLE_2, KEY_ROWID2 + 
      "=" + rowId2, null) > 0;
}

//method for retrieving all the inputs from database
public Cursor getAllLogin() 
{
    return db.query(DATABASE_TABLE, new String[] {
      KEY_ROWID, 
      KEY_USER,
      KEY_PASSWORD,         
      KEY_NUMBER,
      KEY_STATUS,},
            null, 
            null, 
            null, 
            null, 
            null, 
            null);
}   

public Cursor getAllEntry() 
{
    return db.query(DATABASE_TABLE_2, new String[] {
      KEY_ROWID2,
      KEY_TITLE,
      KEY_ENTRY,
      KEY_DATE,
      KEY_TIME},
            null, 
            null, 
            null, 
            null, 
            null, 
            null);
}

//---retrieves a particular title---
public Cursor getLogin(long rowId) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE, new String[] {
              KEY_ROWID,
              KEY_USER, 
              KEY_PASSWORD,
              KEY_NUMBER,
              KEY_STATUS,}, 
              KEY_ROWID + "=" + rowId, 
              null,
              null, 
              null, 
              null, 
              null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

public Cursor getEntry(long rowId2) throws SQLException 
{
    Cursor mCursor =
            db.query(true, DATABASE_TABLE_2, new String[] {
              KEY_ROWID2,
              KEY_TITLE,
              KEY_ENTRY,
              KEY_DATE,
              KEY_TIME}, 
              KEY_ROWID2 + "=" + rowId2, 
              null,
              null, 
              null, 
              null, 
              null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}


//---updates a title---
public boolean updateLogin(long rowId, String user, String pass, String no, String status) 
{
    ContentValues args = new ContentValues();
    args.put(KEY_USER, user);
    args.put(KEY_PASSWORD, pass);
    args.put(KEY_NUMBER, no);
    args.put(KEY_STATUS, status);
    return db.update(DATABASE_TABLE, args, 
                     KEY_ROWID + "=" + rowId, null) > 0;
}

public boolean updateEntry(long rowId, String title, String entry, String date, String time) 
     {
         ContentValues args = new ContentValues();
         args.put(KEY_TITLE, title);
         args.put(KEY_ENTRY, entry);
         args.put(KEY_DATE, date);
         args.put(KEY_TIME, time);
         return db.update(DATABASE_TABLE_2, args, 
                          KEY_ROWID2 + "=" + rowId, null) > 0;
     }

}