java.lang.IllegalStateException: Fragment bb{42261900} not attached to Activity
A.处理异常java.lang.IllegalStateException: Fragment bb{42261900} not attached to Activity
处理方式:由于在线程中调用Fragment以下方法会出现fragment已经没有附加到activity,
所以在调用这些方法时候加isAdded()判断
Fragment源码
--------------------1-----------------------------
public final Resources getResources()
{
if (this.mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
return this.mActivity.getResources();
}
public final CharSequence getText(int resId)
{
return getResources().getText(resId);
}
public final String getString(int resId)
{
return getResources().getString(resId);
}
public final String getString(int resId, Object[] formatArgs)
{
return getResources().getString(resId, formatArgs);
}
-----------------2--------------------
public LoaderManager getLoaderManager()
{
if (this.mLoaderManager != null) {
return this.mLoaderManager;
}
if (this.mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
this.mCheckedForLoaderManager = true;
this.mLoaderManager = this.mActivity.getLoaderManager(this.mWho, this.mLoadersStarted, true);
return this.mLoaderManager;
}
-----------------3--------------------
public void startActivity(Intent intent)
{
if (this.mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
this.mActivity.startActivityFromFragment(this, intent, -1);
}
-----------------4--------------------
public void startActivityForResult(Intent intent, int requestCode)
{
if (this.mActivity == null) {
throw new IllegalStateException("Fragment " + this + " not attached to Activity");
}
this.mActivity.startActivityFromFragment(this, intent, requestCode);
}
java.lang.IllegalStateException: Fragment bb{42261900} not attached to Activity的更多相关文章
- java.lang.IllegalStateException:Fragment XXXFragment{409864b0} not attached to Activity
现象: 这类bug产生的现象就是在Fragment还没添加到Activity中时,去调用了Fragment的getResources().getString(R.string.xxx)这样的函数. 原 ...
- Android 学习之异常总结--java.lang.IllegalStateException:Could not execute method of the activity
在android学习过程中通常会遇到java.lang.IllegalStateException:Could not execute method of the activity这个错误:非法状态的 ...
- [Android Pro] java.lang.IllegalStateException: Fragment(XXFragment) not attached to Activity异常
转载:http://blog.csdn.net/winson_jason/article/details/20357435 下边两个问题,是在开发中碰到的一些关于Fragment的偶发性的问题,今天时 ...
- Android - 错: java.lang.IllegalStateException: Already attached
错: java.lang.IllegalStateException: Already attached 本文地址: http://blog.csdn.net/caroline_wendy 可能原因: ...
- java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
在ViewPager中,用Fragment显示页面时,报错: java.lang.IllegalStateException: The specified child already has a pa ...
- java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState问题解决
(1)我用的是fragment,在onStop但是没有onDestroy的情况下切换(replace)fragment时报 java.lang.IllegalStateException: Can n ...
- myeclipse 无法启动 java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
把myeclipse10 按照目录完整拷贝到了另外一台电脑, 另外的目录 原安装目录 D\:\soft\i\myeclipse10 新安装目录 E\:\soft\myeclipse10 双击启动失败, ...
- java.lang.IllegalStateException:Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxx...}: java.lang.IllegalSta ...
- java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead
java.lang.IllegalStateException: Not allowed to create transaction on sharedEntityManager - use Spri ...
随机推荐
- sonarqube 代码检查
再好的程序员也会出bug,所以代码检查很有必要.今天就出一个简单的检查工具代替人工检查. 参考: http://www.cnblogs.com/qiaoyeye/p/5249786.html 环境及版 ...
- 深入理解Linux网络技术内幕——PCI层和网络接口卡
概述 内核的PCI子系统(即PCI层)提供了不同设备一些通用的功能,以便简化各种设备驱动程序. PCI层重要结构体如下: pci_device_id 设备标识,根据PCI标志定 ...
- php 函数2
- centos 7安装tomcat
1.下载安装包 http://tomcat.apache.org/download-80.cgi 2.安装tomcat 注:安装前需要安装jdk环境 #解压 [root@localhost soft] ...
- Python range
i = 1 while i <= 100: print(i) i += 1 # range(参数) [0,参数) 取不到 for i in range(10): # range() 可以被迭代 ...
- Vue实例的的data对象
介绍 Vue的实例的数据对象data 我们已经用了很多了,数据绑定离不开data里面的数据.也是Vue的核心属性. 它是Vue绑定数据到HTML标签的数据源泉,另外Vue框架会自动监视data里面的数 ...
- Linux文件共享(单进程之间、多进程之间)
转载:https://www.cnblogs.com/frank-yxs/p/5925603.html 在同一个进程中,实现文件共享的方法有两种: 多次使用open函数打开相同文件 使用dup/dup ...
- CTC+pytorch编译配置warp-CTC
CTC CTC可以生成一个损失函数,用于在序列数据上进行监督式学习,不需要对齐输入数据及标签,经常连接在一个RNN网络的末端,训练端到端的语音和文本识别系统.CTC论文地址:http://www.cs ...
- Android manifest 获取源代码
/********************************************************************************* * Android manifes ...
- [LeetCode&Python] Problem 872. Leaf-Similar Trees
Consider all the leaves of a binary tree. From left to right order, the values of those leaves form ...