-4
@Override
public void onAttach(Activity activity) {
    super.onAttach(activity);
    try {
        activitycomander = (TopSectionListener) activity;
    }catch (ClassCastException e){
        throw new ClassCastException(activity.toString());
    }
}

This is the code of my java class linking with MainActivity. There is issue with onAttach method in Android Studio. It shows as strike-through with the message:

onAttach (android.app.activity) is deprecated:

I'm also having a second issue in MainActivity:

 public void createMeme(String top, String bottom){
    bottomsection fragmentbottom = (bottomsection) getSupportFragmentManager().findFragmentById(R.id.fragment2);
    fragmentbottom.setMemeText(top, bottom);
}

topsection and bottomsection are the names of my java classes, they are highlighted red with the message cannot resolve method.

I have done a clean rebuild on my project and checked the option to add or remove the imports automatically.

Cœur
  • 37,241
  • 25
  • 195
  • 267
abdul
  • 1
  • 2

1 Answers1

0

First question regarding onAttach is a duplicate of Android Fragment onAttach() deprecated

Regarding topsection and bottomsection, Classes should always begin with a capital letter and use CamelCaps, as per the Naming Conventions. So rename them to TopSection and BottomSection.

Also check if your class has been imported - if bottomsection is underlined then try Alt+Enter and select Import Class

Anatoly Shamov
  • 2,608
  • 1
  • 17
  • 27
Michael Dodd
  • 10,102
  • 12
  • 51
  • 64