gpt4 book ai didi

android - fragment 错误: incompatible types, 需要android.app.fragment 但找到activity.messagefragment

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:19:57 37 4
gpt4 key购买 nike

 @Override
public void onDrawerItemSelected(View view, int position) {
displayView(position);
}

private void displayView(int position) {
Fragment fragment = null;
String title = getString(R.string.app_name);
switch (position) {
case 0:
fragment = new HomeFragment();
title = getString(R.string.title_home);
break;
case 1:
fragment = new FriendsFragment();
title = getString(R.string.title_friends);
break;
case 2:
fragment = new MessageFragment();
title = getString(R.string.title_messages);
break;
default:
break;
}

打印的错误是:

incompatible types,required android.app.fragment but found activity.messagefragment

最佳答案

在您的 messagefragment 类中,您需要导入

import android.app.Fragment;

代替

import android.support.v4.app.Fragment;

关于android - fragment 错误: incompatible types, 需要android.app.fragment 但找到activity.messagefragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32496248/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com