The database creation and adding entries are working fine...but now I'm having a problem displaying the data stored in my database.
The error when I execute the display part is the 'NullPointerException' error..
here is some of the relevant code :
Using java Syntax Highlighting
- public void addentry(String servIP, String port)
- {
- Date d = new Date();
- String cdate = new String(d.toString());
- String entry = new String();
- ContentValues v = new ContentValues();
- v.put("login_time", cdate);
- entry = servIP + ":" + port;
- v.put("serverIP", entry);
- myDB.insert(MY_DATABASE_TABLE, null, v);
- myDB.close();
- }
- public Cursor GetAllRows() {
- try {
- return myDB.query(MY_DATABASE_TABLE, new String[] {
- "login_time", "serverIP"}, null, null, null, null, null);
- } catch (SQLException e) {
- return null;
- }
- }
- public void viewdb()
- {
- Cursor c;
- try {
- myDB = ctx1.openDatabase(MY_DATABASE_NAME, null);
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- c = GetAllRows();
- startManagingCursor(c);
- ListAdapter adapter = new SimpleCursorAdapter(
- ctx1,
- R.layout.displaylog,
- c,
- new String[] {"login_time", "serverIP"},
- new int[] {R.id.col1, R.id.col2}
- );
- setListAdapter(adapter);
- myDB.close();
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


