1

Android studio does not recognize a method within my code.

I implemented a method to handle the call.

private void saveDeal(){ String title = textTitle.getText().toString(); String description = textDescription.getText().toString(); String price = textPrice.getText().toString(); TravelDeal deal = new TravelDeal(title, description, price, ""); mDatabaseReference.push().setValue(deal); } private void clean(){ textTitle.setText(""); textDescription.setText(""); textPrice.setText(""); textTitle.requestFocus(); } 

But in the method call,

public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.menu_save: saveDeal(); Toast.makeText(this, "Deal saved", Toast.LENGTH_LONG); clean(); return true; default: return super.onOptionsItemSelected(item); } 

saveDeal() and clean() are still showing in red in the switch block.

3
  • 3
    Are these methods in the same class? Commented Aug 5, 2019 at 16:03
  • Yes. They both belong to the same class. Commented Aug 5, 2019 at 16:09
  • 1
    Can you post your whole class code? Commented Aug 5, 2019 at 16:31

2 Answers 2

1

Found a solution. I missed a closing curly bracket in the switch statement in the onOptionsItemsSelectedMenu() method.

Sign up to request clarification or add additional context in comments.

Comments

0

From Android Studio Menu, Try File->Invalidate Caches/Restart->Invalidate and Restart

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.