0
onAttach方法中出現「Incompatible types」錯誤。我試圖在這裏創建接口,但不知道爲什麼會發生這種情況,我認爲我做到了正確的方式。而且當我調用「createMeme」方法時,它給了我錯誤,「不解析這種方法」,而這種方法我公開。理解我的問題比plz問的任何混淆,我是一個可怕的提問者任何方式。任何人有任何想法?感謝提前:)在onAttach方法中創建接口時出錯
public class TopSectionFragment extends Fragments
{
private static EditText toptextInput;
private static EditText bottomtextInput;
TopSectionFragment activityCommander;
public interface TopSectionListener
{
public void createMeme(String topText, String bottomText);
}
@Override
@SuppressWarnings("deprecation")
public void onAttach(Activity activity)
{
super.onAttach(activity);
try {
activityCommander = (TopSectionListener) activity;//error here
}catch(ClassCastException e)
{
throw new ClassCastException (activity.toString());
}
}
首先, ,'onAttach'這個聲明被棄用,它應該以'Context context'作爲參數。其次,展示你的活動。它是否實現了'TopSetionListener' – Vucko
也許你沒有實現TopSectionListener到Activity? – Andreyua
@Andreyua我實現了它。但它仍然給出同樣的錯誤。因此我改變了activityCommander的類型並刪除了錯誤。 –