Bradly Spicer
Bradly Spicer

Reputation: 2318

Weird catlog provides no explanation

Recently started getting a rather odd Catlog which doesn't describe what's going wrong very well.

I have it posted here: http://pastie.org/9415113

Line 55:

        DebugCarTxt = (EditText) findViewById(R.id.DebugCar);

        // you should  instantiate 'DatabaseHandler'  here
        DatabaseHandler db = new DatabaseHandler(this); // "this" refer to the context
        Car cars = db.getCurrentCar();

        db.createCar(new Car(cars.get_id(),cars.get_address(),cars.get_postcode(),cars.get_image()));
//this is line 55       String rows= "id : "+ cars.get_id()+ " address : "+cars.get_address() + "postcode : "+cars.get_postcode()+" image : "+cars.get_image();

This is my getCurrentCar() {};

public Car getCurrentCar() {

    SQLiteDatabase db       =   getWritableDatabase();
    String sql              = "SELECT " + KEY_ID + "," + KEY_IMAGE + " FROM " + TABLE_CARS + " ORDER BY RANDOM() LIMIT 1";
    Cursor cursor           =   db.rawQuery(sql, new String[] {});
    Car car = null;

    try {
        if (cursor.moveToFirst()) {
            car = new Car(Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), cursor.getString(3));
        }
    }
    finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
            db.close();
    }
    return car;
}

Am I right to assume it's calling a null because there isn't anything in the database?

Upvotes: 0

Views: 54

Answers (1)

kevkev97kk
kevkev97kk

Reputation: 66

One of the values you are getting is set as null.


Edit: MY fault, I believe that it is the Car that is null. You should check if there are any values set as null by:

if(car == null) { //and etc for other get method.
    //Use Logs here to print error on logcat.
}

This should help identifying which value is null.

Info on Logs: http://developer.android.com/reference/android/util/Log.html

Upvotes: 2

Related Questions