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

這是我的java類與MainActivity鏈接的代碼。 Android Studio中存在onAttach方法問題。它顯示爲劃掉與消息:android.support.v4.app.fragment覆蓋棄用的方法

onAttachandroid.app.activity)被棄用:

我也有在MainActivity第二個問題:

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

topsectionbottomsection是我的java類的名稱,它們用消息cannot resolve method突出顯示爲紅色。

我已經在我的項目上做了一個乾淨的重建,並選中了自動添加或刪除導入的選項。

+0

請告訴我問題嗎? – Enzokie

回答

0

關於onAttach第一個問題是Android Fragment onAttach() deprecated

關於topsectionbottomsection重複,類應總是以大寫字母開頭,並且使用CamelCaps,按照該Naming Conventions。因此將它們重命名爲TopSectionBottomSection

同時檢查如果你的類已經被導入 - 如果bottomsection加下劃線,然後嘗試Alt + Enter鍵並選擇進口類

相關問題