Search code examples
androidrubyrubymotion

NoMethodError undefined method `oncreateOptionsMenu` for true:Boolean


I'm getting the following NoMethodError exception within a very basic RubyMotion app calling onCreateOptionsMenu and I'm not sure what is wrong with this.

E/com/yourcompany/hello( 5404): Exception raised: NoMethodError: undefined method `onCreateOptionsMenu' for true:Boolean
E/com/yourcompany/hello( 5404):         from main_activity.rb:19 in `onCreateOptionsMenu'

This is the RubyMotion method I have defined

def onCreateOptionsMenu(menu)
  getMenuInflater().inflate(resources.getIdentifier('my', 'menu', 'com.yourcompany.hello'), menu)
  return(super.onCreateOptionsMenu(menu))
end

I'm also including a working Java equivalent that I created as a comparison, if that is of any help.

@Override
public boolean onCreateOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.my, menu);
    return(super.onCreateOptionsMenu(menu));
}

Solution

  • In Ruby, super calls the same method in the parent class.

    So this line in your code:

    super.onCreateOptionsMenu(menu)

    should be just this:

    super(menu)