java.lang.IllegalStateException: Fragment not attached to Activity

当在A Fragment里面调用B Framgent的某个方法的时候,B Fragment的上下文对象为空:getActivity() == null ,这种情况下就会报这个错误。

解决办法:

		if (!isAdded()) {
			return;
		}
		if (!HttpHelper.isNetworkConnected(getActivity())) {
			toast(getString(R.string.toast_netwrok_disconnected));
			return;
		}

就是在调用getActivity()之前判断Fragment是否已经Add到Activity就可以了

你可能感兴趣的:(java.lang.IllegalStateException: Fragment not attached to Activity)