android.app.FragmentManager 与 android.support.v4.app.FragmentManager带来的若干Error
Fragment是activity的界面中的一部分或一种行为。你能够把多个Fragment们组合到一个activity中来创建一个多面界面而且你能够在多个activity中重用一个Fragment。你能够把Fragment觉得模块化的一段activity,它具有自己的生命周期,接收它自己的事件。并能够在activity执行时被加入或删除。
一个好的帖子:http://my.oschina.net/u/270164/blog/85347。
使用Fragment的包为android.app.FragmentManager,可是因为其对3.0下版本号不兼容,所以要
引入android.support.v4.app.FragmentManager 两个包对Fragment同样方法的定义有所不同,因此在import时,常常easy混淆导致程序报错。以下就来总结下:
1、编译无错误,执行时报错:android.view.InflateException: Binary XML file line #7: Error inflating class fragment
出现了上述错误,原因往往是你在某个.xml文件使用了<fragment>标签,但相应的xx.java文件里import的却是android.support.v4.app.Fragment。android.support.v4.app.Fragment:能够兼容到1.6的版本号,不能使用<fragment>标签,须要在程序中通过add或者replace的方式加入。
2、编译错误:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
childFm=getSupportFragmentManager();
}
代码如上。在add处提示:The
method add(Fragment, String) in thetype FragmentTransaction is not applicable for the arguments (Frag1, String)。
原因:我的Frag1.java中。import的包是 android.app.Fragment所以报错。
改成import android.support.v4.app.Fragment;就好了。
3、此外,在调用Activity时,包为 android.support.v4.app.FragmentActivity的类,都extends的是FragmentActivity而不是Activity。
android.app.FragmentManager 与 android.support.v4.app.FragmentManager带来的若干Error的更多相关文章
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...
- Android fragment切换后onresume时报 Attempt to write to field 'int android.support.v4.app.Fragment.mNextAnim'
动态加载fragment以后,调用了remove方法移除Fragment,在返回来的时候报 Attempt to write to field 'int android.support.v4.app. ...
- android.app.Fragment与android.support.v4.app.Fragment不一致
在看法中用到的Fragment在类型转换的时候非常easy出现这样的问题: 对照代码: class MyFragmentPagerAdapter extends FragmentPagerAdapte ...
- 在布局中使用android.support.v4.app.Fragment的注意事项
1.Activity必须继承android.support.v4.app.FragmentActivity 2.fragment标签的name属性必须是完全限定包名,如下: <LinearLay ...
- app:transformClassesWithJarMergingForDebug uplicate entry: android/support/v4/app/BackStackState$1.class
.Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api. ...
- android.support.v4.app.Fragment和android.app.Fragment区别
1.最低支持版本不同 android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版 android.support.v ...
- 安卓开发错误:The type android.support.v4.app.TaskStackBuilder$SupportParentable cannot be resolved.
今天在使用低版本下的ActionBar,在继承ActionBarActivity时报了"The type Android.support.v4.app.TaskStackBuilder$Su ...
- [转]android.support.v4.app.Fragment和android.app.Fragment区别
1.最低支持版本不同 android.app.Fragment 兼容的最低版本是android:minSdkVersion="11" 即3.0版 android.support ...
- android.support.v4.app.Fragment vs android.app.Fragment 的区别
android.support.v4.app.Fragment vs android.app.Fragment 的区别 我开过平板相关应用,用了Fragment来处理.后来重新开发另外一个应用,直接引 ...
随机推荐
- AtcoderGrandContest 016 D.XOR Replace
$ >AtcoderGrandContest \space 016 D.XOR\space Replace<$ 题目大意 : 有两个长度为 \(n\) 的数组 \(A, B\) ,每次操作 ...
- 51nod2000 四边形分割平面 规律题
观察样例,$ans(1) = 1, ans(2) = 10$,再手推一组,$ans(3) = 26$ 可以发现规律$ans(n) = (2n - 1)^2 + 1$ 如果还是没看出规律,那么打个程序去 ...
- BZOJ 1395 [Baltic2005]Trip(最短路+DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1354 [题目大意] 给出一些车的班次,包括起点,终点,到达起点时间区间, 到达终点时间 ...
- windows下eclipse搭建android_ndk开发环境
安装cygwin: 由于NDK编译代码时必须要用到make和gcc,所以你必须先搭建一个linux环境, cygwin是一个在windows平台上运行的unix模拟环境,它对于学习unix/linux ...
- noip200807传纸条
试题描述: 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的 ...
- 【原】Eclipse更改字符编码,精华版
- 线程,线程安全与python的GIL锁
今天看到一篇文章,讲述的是几个提升python性能的项目:传送门 在看的过程中,接触到一个名词,一个从学python开始就一直看到,但是从来都是一知半解的名词,心里不开心,必须把它搞明白,对了,这个词 ...
- 【张宴】PHP在金山游戏运营中的应用
PPT下载地址1(国外服务器):http://blog.s135.com/attachment/201105/2011phptc_zy.zip PPT下载地址2(国内服务器):http://ishar ...
- MySQL在windows系统的安装
原文:https://blog.csdn.net/wokaowokaowokao12345/article/details/76736152 MySQL在windows系统的安装 原创 2017年08 ...
- Unity5.0与Android交互
1. 目标 1) Unity3D可调用Android Java函数(在.jar中) 2) Java可调用Unity3D函数 3) Unity3D可调用Android C函数(在.so中) 2. 测试环 ...