Can't call function from within onOptionsItemSelected

Posted by Kristy Welsh on Stack Overflow See other posts from Stack Overflow or by Kristy Welsh
Published on 2012-10-28T21:09:27Z Indexed on 2012/10/28 23:02 UTC
Read the original article Hit count: 225

Filed under:
|
public boolean onOptionsItemSelected(MenuItem item)
{
    //check selected menu item
    switch (item.getItemId()) { 
    case R.id.exit:
        this.finish();
        return true;
    case R.id.basic: 
        Difficulty = DIFFICULTY_BASIC;
        Toast.makeText(YogaPosesActivity.this, "Difficulty is Basic", Toast.LENGTH_SHORT).show();
        SetImageView(myDbHelper);
        return true;
    case R.id.advanced: 
        Toast.makeText(YogaPosesActivity.this, "Difficulty is Advanced", Toast.LENGTH_SHORT).show();
        Difficulty = DIFFICULTY_ADVANCED;
        SetImageView(myDbHelper);
        return true;
    case R.id.allPoses:
        Toast.makeText(YogaPosesActivity.this, "All Poses Will Be Displayed", Toast.LENGTH_SHORT).show();
        Difficulty = DIFFICULTY_ADVANCED_AND_BASIC;
        SetImageView(myDbHelper);
        return true;
    default: 
       return super.onOptionsItemSelected(item);
    }
}

I get an error when I call the SetImageView function, which was defined out of the OnCreate Activity. Can you not call a function unless it was defined inside the OnCreate?

I get a nullPointer Exception when calling the function.

© Stack Overflow or respective owner

Related posts about android

Related posts about options-menu