错误片段 [英] Error in Fragment

查看:112
本文介绍了错误片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写方案用一个简单的片段,我得到了一个错误如下:

I'm writing programs with a simple Fragment and I got an error as below:

FrameLayout fl=new FrameLayout(this);
fl.setId(0x1024);

setContentView(fl);
FragmentTransaction ftransc=getFragmentManager().beginTransaction();
FragmentTest2 myFragment=new FragmentTest2();
ftransc.add(fl.getId(), myFragment, "FirstFragment");
ftransc.commit();

添加方法,我得到一个红色波浪线和下面的错误显示:

Under the add method I get a red squiggly line and the following error shows:

该方法添加(INT,片段,字符串中的类型 FragmentTransaction 不适用于参数(INT,FragmentTest2,字符串)

The method add(int, Fragment, String in the type FragmentTransaction is not applicable for the arguments (int, FragmentTest2, String).

我在做什么错了?

推荐答案

这个问题通常当你混淆了兼容包片段和Android 片段。如果您尝试使用兼容性片段,请确保您导入 android.support.v4.app.Fragment ,否则请确保您导入的android .app.Fragment 。同样做相同的 FragmentTransaction

This problem usually occurs when you mix up the compatibility package Fragment and the Android Fragment. If you are trying to use the compatibility Fragment, make sure that you import android.support.v4.app.Fragment, otherwise make sure you import android.app.Fragment. Similarly do the same with FragmentTransaction.

这篇关于错误片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆