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 ...
随机推荐
- AVAudioPlayer播放音频文件时没声音
AVAudioPlayer播放一个mp3文件时,居然没有声音.mp3文件是放在工程里面的,路径没有错误但就是死活没有声音. func playSound() { let notifyUrl = NSB ...
- [LeetCode&Python] Problem 590. N-ary Tree Postorder Traversal
Given an n-ary tree, return the postorder traversal of its nodes' values. For example, given a 3-ary ...
- win8转win7+真正解决 “安装程序无法定位现有系统分区,也无法创建新的系统分区”的方法
问题情况:win8电脑转win7系统,出现问题:“安装程序无法定位现有系统分区,也无法创建新的系统分区” 第一种:猜测可行的方法: 1.老毛桃U盘启动电脑,进入PE系统后,直接使用Diskgeni ...
- LOJ2537. 「PKUWC2018」Minimax【概率DP+线段树合并】
LINK 思路 首先暴力\(n^2\)是很好想的,就是把当前节点概率按照权值大小做前缀和和后缀和然后对于每一个值直接在另一个子树里面算出贡献和就可以了,注意乘上选最大的概率是小于当前权值的部分,选最小 ...
- 利用spring-mail模块发送带附件邮件dome
本例为maven项目,直接撸代码吧. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi ...
- HDU 1084:What Is Your Grade?
Problem Description "Point, point, life of student!" This is a ballad(歌谣)well known in col ...
- HDU 1872:稳定排序
稳定排序 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...
- Fzu软工第二次作业-词频分析
(0)前言: Github项目 作业地址 (1)PSP表格: PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 ...
- MySQL的innoDB锁机制以及死锁处理
MySQL的nnoDB锁机制 InnoDB与MyISAM的最大不同有两点:一是支持事务(TRANSACTION):二是采用了行级锁.行级锁与表级锁本来就有许多不同之处,innodb正常的select ...
- systemd学习笔记
一.systemd介绍 systemd即为system daemon,是linux下的一种init软件与多数发行版使用的System V风格init相比,systemd采用了以下新技术: (1) 采用 ...