• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Debug opens when clicking on a spinner that is connected with database

santhoshp

Lurker
My simple application has a spinner in which i updated some datas from database. When i click on the spinner debug opens. My code for loading spinner is below and i attached the screen shot of the Debug opened. I am using Windows-OS, Eclipse 3.5 , Android API-8


//Open a database

db=SQLiteDatabase.openDatabase("data/data/com.android.layout/MyStorage", null, SQLiteDatabase.CREATE_IF_NECESSARY);

db.beginTransaction();

//Desired column to be loaded from DB to spinner

String[] columns = {"username"};


Cursor c = db.query("tbleprof",columns,null,null,null,null,null);

startManagingCursor(c);

//Take a vector to hold the values from database to an array

Vector<String> values = new Vector<String>();


while(c.moveToNext()){

//Add elements to the Vector array

values.addElement(c.getString(0));


}
db.endTransaction();

//Copy the Vector to a String array so that it can be given to the adapter to load the data to spinner

int length = values.size();

String[] valuesForSpinner = new String[length];

values.copyInto(valuesForSpinner);

//Configuring the Spinner

ArrayAdapter<CharSequence> spinnerAdapter = new ArrayAdapter<CharSequence>(getApplicationContext(), android.R.layout.simple_spinner_item);

spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinner.setAdapter(spinnerAdapter);

//Adding elements to the adapter from the String array

for(int i = 0;i < valuesForSpinner.length;i++){


spinnerAdapter.add(valuesForSpinner);

}

} catch (Exception e) {

// TODO: handle exception
e.printStackTrace();


}finally{
db.close();

}
 
Back
Top Bottom