Search code examples
androidandroid-activity

Android cannot resolve method getActivity()


    fileHippoWrapper = (LinearLayout) findViewById(R.id.filehippo_wrapper2);
    fileHippoWrapper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(FinalChatActivity.this, "FileHippo", Toast.LENGTH_SHORT).show();
            AlAttachmentOptions.processLocationAction(getActivity(), null);

        }
    });

I'm not able import function processLocationAction from another activity AlAttachmentOptions it says

can't resolve method getActivity()


Solution

  • There is no getActivity() method in Android Activity. This is just to indicate that you need to get reference of your activity here.

    So instead of getActivity(), use this Or FinalChatActivity.this. It will work.

    So your code will:

    fileHippoWrapper = (LinearLayout) findViewById(R.id.filehippo_wrapper2);
    fileHippoWrapper.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(FinalChatActivity.this, "FileHippo", Toast.LENGTH_SHORT).show();
            AlAttachmentOptions.processLocationAction(FinalChatActivity.this, null);
    
        }
    });