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来处理.后来重新开发另外一个应用,直接引 ...
随机推荐
- 【BZOJ 3294】 3294: [Cqoi2011]放棋子 (DP+组合数学+容斥原理)
3294: [Cqoi2011]放棋子 Description Input 输入第一行为两个整数n, m, c,即行数.列数和棋子的颜色数.第二行包含c个正整数,即每个颜色的棋子数.所有颜色的棋子总数 ...
- Ubuntu系统 安装谷歌 Chrome 浏览器
在 Ubuntu 16.04 中安装谷歌 Chrome 浏览器,步骤: 1.sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P / ...
- luoguP1354房间最短路问题
判断两点间连通性,建图跑floyed #include<bits/stdc++.h> using namespace std; ; struct node { ],x; }q[N];dou ...
- [BZOJ5093]图的价值(NTT+第二类Stirling数)
5093: [Lydsy1711月赛]图的价值 Time Limit: 30 Sec Memory Limit: 256 MBSubmit: 250 Solved: 130[Submit][Sta ...
- Java并发(七):双重检验锁定DCL
双重检查锁定(Double Check Lock,DCL) 1.懒汉式单例模式,无法保证线程安全: public class Singleton { private static Singleton ...
- AC自动机详解(附加可持久化AC自动机)
AC自动机 AC自动机,说白了就是在trie树上跑kmp(其实个人感觉比kmp容易理解).是一种多匹配串,单个主串的匹配.概括来说,就是将多个匹配串构造一个trie树,对于每个trie树的节点构造nx ...
- Djangio笔记
django图解 新创建一个项目后的目录层级
- uoj 41 【清华集训2014】矩阵变换 婚姻稳定问题
[清华集训2014]矩阵变换 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/41 Description 给出 ...
- MySQL 之 Index Condition Pushdown(ICP)
简介 Index Condition Pushdown (ICP)是MySQL 5.6 版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式. 当关闭ICP时,index 仅仅是data ...
- CC1101是一种低成本真正单片的UHF收发器
CC1101是一种低成本真正单片的UHF收发器,为低功耗无线应用而设计.电路主要设定为在315.433.868和915MHz的ISM(工业,科学和医学)和SRD(短距离设备)频率波段,也可以容易地设置 ...