Emmanuel Ani
Emmanuel Ani

Reputation: 121

Cannot resolve private void method

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.

Upvotes: 1

Views: 464

Answers (2)

Emmanuel Ani
Emmanuel Ani

Reputation: 121

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

Upvotes: 1

touhid udoy
touhid udoy

Reputation: 4442

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

Upvotes: 0

Related Questions