0

I have this code in my onCreate and I get a null pointer exception if I uncomment the sortMode(position) line. The log works just fine though, which seems weird to me. What am I doing wrong?

I want it to call sortMode() when an option on the spinner is selected.

    sort_spinner = (Spinner) findViewById(R.id.sort_spinner);
    sort_spinner
    .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView adapter, View v,
                int position, long lng) {
            Log.i("position ", position + "");
            //sortMode(position);
        }

        @Override
        public void onNothingSelected(AdapterView arg0) {
            // do something else
        }
    }); 
GrilledCheese
  • 311
  • 3
  • 8
  • 13
  • How does the method `sortMode` look like? Where exactly is NPE thrown? Having NPE here is not possible as `position` is a primitive. – kar Feb 14 '13 at 22:20
  • I just edited my code and the null is on both the sortMode(position) and the the first line of scoreMode(). – GrilledCheese Feb 14 '13 at 22:45
  • can you post the logcat? – DigCamara Feb 14 '13 at 22:47
  • I just figured out the problem. I was converting this from a menu option to a spinner and I still had code that changed the menu text, which doesn't exist. Once I removed it, it works again. – GrilledCheese Feb 14 '13 at 22:48

1 Answers1

0

I was converting from a menu item to a spinner and forgot to take out this code:

menuSortBy.setTitle(R.string.sort_by_score);

Once I removed that, it worked.

GrilledCheese
  • 311
  • 3
  • 8
  • 13