Question

I am getting a null pointer exception when i am running this peice of code

            private void loadSpinnerData() {
        // database handler
        AttendAppDatasource db = new AttendAppDatasource(getApplicationContext());

        // Spinner Drop down elements
        List<String> clas = db.viewCol(AttendAppDbOpenHelper.COLUMN_CLASS);
        Log.i("Select Class","List Assigned");
        // Creating adapter for spinner
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, clas);

        // Drop down layout style - list view with radio button
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        // attaching data adapter to spinner
        spinner.setAdapter(dataAdapter);
    }

this is the relevant log output

enter image description here

this is the log out put corresponding to the list enter image description here

Was it helpful?

Solution

Your spinner is set to null. You need to get it from your resources

Spinner spinner = (Spinner) findViewById(R.id.'spinner_id_name');

Then you can set your adapter :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top