Problem with displaying the database contents.

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Problem with displaying the database contents.

Postby totw » Thu Apr 02, 2009 4:12 pm

I have created a database for my application to store some log data.
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 :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.     public void addentry(String servIP, String port)
  5.  
  6.     {
  7.  
  8.         Date d = new Date();
  9.  
  10.         String cdate = new String(d.toString());
  11.  
  12.         String entry = new String();
  13.  
  14.         ContentValues v = new ContentValues();
  15.  
  16.         v.put("login_time", cdate);
  17.  
  18.         entry = servIP + ":" + port;
  19.  
  20.         v.put("serverIP", entry);
  21.  
  22.         myDB.insert(MY_DATABASE_TABLE, null, v);
  23.  
  24.         myDB.close();
  25.  
  26.    
  27.  
  28.     }
  29.  
  30.    
  31.  
  32.     public Cursor GetAllRows() {
  33.  
  34.         try {
  35.  
  36.            
  37.  
  38.             return myDB.query(MY_DATABASE_TABLE, new String[] {
  39.  
  40.                     "login_time", "serverIP"}, null, null, null, null, null);
  41.  
  42.            
  43.  
  44.         } catch (SQLException e) {
  45.  
  46.             return null;
  47.  
  48.         }
  49.  
  50.     }
  51.  
  52.  
  53.  
  54.     public void viewdb()
  55.  
  56.     {
  57.  
  58.         Cursor c;
  59.  
  60.         try {
  61.  
  62.                         myDB = ctx1.openDatabase(MY_DATABASE_NAME, null);
  63.  
  64.                 } catch (FileNotFoundException e) {
  65.  
  66.                         // TODO Auto-generated catch block
  67.  
  68.                         e.printStackTrace();
  69.  
  70.                 }
  71.  
  72.         c = GetAllRows();
  73.  
  74.         startManagingCursor(c);
  75.  
  76.         ListAdapter adapter = new SimpleCursorAdapter(
  77.  
  78.                         ctx1,
  79.  
  80.                         R.layout.displaylog,
  81.  
  82.                         c,
  83.  
  84.                         new String[] {"login_time", "serverIP"},
  85.  
  86.                         new int[] {R.id.col1, R.id.col2}
  87.  
  88.                         );
  89.  
  90.         setListAdapter(adapter);
  91.  
  92.         myDB.close();
  93.  
  94.    
  95.  
  96.     }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
User avatar
totw
Developer
Developer
 
Posts: 27
Joined: Tue Mar 31, 2009 10:35 am

Top

Postby Alexandro » Fri Apr 03, 2009 8:26 am

NullPointers are the easiest to track down. Use debug mode to find the missing object.
Alexandro
Junior Developer
Junior Developer
 
Posts: 24
Joined: Thu Mar 05, 2009 5:42 pm

Postby totw » Fri Apr 03, 2009 11:02 am

i tried changing the context from 'ctx1' in the above code to 'this'.. the error message changes to 'not supported in system context'

in debug mode, 'this' has 'InvocationTargetException' error..
User avatar
totw
Developer
Developer
 
Posts: 27
Joined: Tue Mar 31, 2009 10:35 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 4 guests