我在向MainActivity添加片段时遇到问题。
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentActivity;
b1 frag = new b1();
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.my_layout, frag,"ECalc");
transaction.commit();
错误:
The method add(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, b1, String)
如何解决这个问题?
答案 0 :(得分:2)
我怀疑你的b1
类(非常糟糕的命名)来自android.app.Fragment
而不是来自support.v4.app.Fragment
- 如果你的b1类扩展了任何东西......那么改变b1以从支持库扩展片段类。