why I am getting from the database null
from column url
?
I am adding data in sqlite like this
void addObjects(Objects o
In your Objects geturl(String name)
method , change
Cursor cursor = db.query(TABLE_OBJECTS, new String[] {OBJECT_URL,
OBJECT_NAME , OBJECT_CATEGORY, OBJECT_TYPE }, OBJECT_NAME + "=?",
new String[] { String.valueOf(name) }, null, null, null, null);
to
Cursor cursor = db.query(TABLE_OBJECTS, new String[] {OBJECT_ID,
OBJECT_NAME , OBJECT_URL, OBJECT_TYPE }, OBJECT_NAME + "=?",
new String[] { String.valueOf(name) }, null, null, null, null);
Supposing that your Objects class has the following structure:
public class Objects {
private String id;
private String name;
private String url;
private String type;
// methods
}
the tableColumns
argument (new String[] {OBJECT_ID,OBJECT_NAME , OBJECT_URL, OBJECT_TYPE }
) that you pass to the db.query()
method has to respect the same order as in your Objects class (first the id
, 2nd name
, 3rd url
, 4th type
)
Be careful with your datatypes in table definition because MySql datatypes are not supported in SQLite.
Your varchar
fields are supposed to be correct by type affinity but text
is the correct way to store strings, not varchar
or string
.
You defined also datetime
which is not a good idea. Use text
or integer
(with timestamps) instead.