0

I want to retrieve data from database and display it on LOG, here my code:

 String dd = "1/23/2013";

  String sp = "Sky Storm";

 Log.d("Checking",db.getMeterNUmber2(dd,sp).toString());

And getMeterNUmber2 are in DBAdapter and the data that im looking for are in database, so I just want to retrieve it.

My DB Adapter :

public ArrayList<String> getMeterNUmber2(String date , String Vname) throws SQLException {    

    String[] whereArgs = new String[]{date,Vname}; 

    Cursor mcursor = db.rawQuery("SELECT MeterNumber FROM " + SCAN_TABLE + " WHERE  Date = ? AND VendorName = ? ",whereArgs);

    ArrayList<String> results = new ArrayList<String>();
    while (mcursor.moveToNext()) {
        results.add(mcursor.getString(0));
    }

    return results;

}

I'm getting error in logcat:

01-24 19:57:13.590: E/AndroidRuntime(11662): FATAL EXCEPTION: main
01-24 19:57:13.590: E/AndroidRuntime(11662): java.lang.NullPointerException
01-24 19:57:13.590: E/AndroidRuntime(11662):    at scann.barcode.scan.DBAdapter.getMeterNUmber2(DBAdapter.java:303)
01-24 19:57:13.590: E/AndroidRuntime(11662):    at scann.barcode.scan.Result$1.onClick(Result.java:104)
Cœur
  • 37,241
  • 25
  • 195
  • 267
CoT
  • 157
  • 2
  • 13
  • I want to diplay on a LOGCAT – CoT Jan 24 '13 at 19:58
  • Not enough information to determine your problem. Where is the 'new' db created, where do you do a db.open, are you returning a cursor, etc.? – Howard Hodson Jan 24 '13 at 20:01
  • I just used this method to display data from database and using this two values for parameters, so if i put more code here it will make no sense for me, coz I now only this part. – CoT Jan 24 '13 at 20:03
  • 1
    you posted code that does not have the problem. post DBAdapter.getnumberBYDate() on line 303 – user123321 Jan 24 '13 at 20:10

2 Answers2

2

i had the same problem as you and when i look at your log cat

 java.lang.NullPointerException ,

It returning null value , so that means It does not read into your Database,

please check if you have opened your database e.g : db.open() and close

zaamm
  • 178
  • 2
  • 2
  • 8
0

I think you can't just log in logcat ArrayList<String> returned from getMeterNUmber2 because it is a list. You need to retrieve single string values from there first: Best way to convert an ArrayList to a string .

Community
  • 1
  • 1
XorOrNor
  • 8,868
  • 12
  • 48
  • 81