androidfirebaseandroid-snackbarfirebase-invites

Cannot resolve snackbar_layout while adding firebase invitation


I'm trying to add firebase app invitation but getting this error (in the second last line of the code mentioned below):

cannot resolve snackbar_layout

I've already add the dependency: compile 'com.google.firebase:firebase-invites:11.6.0'

Here is the part of the code, where I'm getting this error:

// [START on_activity_result]
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d(TAG, "onActivityResult: requestCode=" + requestCode + ", resultCode=" + resultCode);

    if (requestCode == REQUEST_INVITE) {
        if (resultCode == RESULT_OK) {
            // Get the invitation IDs of all sent messages
            String[] ids = AppInviteInvitation.getInvitationIds(resultCode, data);
            for (String id : ids) {
                Log.d(TAG, "onActivityResult: sent invitation " + id);
            }
        } else {
            // Sending failed or it was canceled, show failure message to the user
            // [START_EXCLUDE]
            showMessage(getString(R.string.send_failed));
            // [END_EXCLUDE]
        }
    }
}
// [END on_activity_result]

private void showMessage(String msg) {
    ViewGroup container = findViewById(R.id.snackbar_layout);
    Snackbar.make(container, msg, Snackbar.LENGTH_SHORT).show();
}

Solution

  • What does the layout of your activity look like?

    you need to have an actual element in your view with an ID of snackbar_layout.

    you are saying, find this view, and then anchor a snackbar into it. but if that view does not exist in your layout, it has nothing to anchor to.

        <View android:id="@+id/snackbar_layout"/>