Attempt to invoke virtual method 'android.os.Handler android.support.v4.app.FragmentHostCallback.getHandler()' on a null object reference
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1588)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:441)
at com.app.rare10.activities.ViewAllMemberActivity.onResume(ViewAllMemberActivity.java:192)
at com.app.rare10.activities.ViewAllMemberActivity$1.onReceive(ViewAllMemberActivity.java:74)
at android.support.v4.content.LocalBroadcastManager.executePendingBroadcasts(LocalBroadcastManager.java:297)
at android.support.v4.content.LocalBroadcastManager.access$000(LocalBroadcastManager.java:46)
at android.support.v4.content.LocalBroadcastManager$1.handleMessage(LocalBroadcastManager.java:116)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698
答案 0 :(得分:2)
我使用布尔值来防止每当活动被销毁并且已经恢复。
boolean hasStop;
.
.
.
.
//here is when I need to prevent
if(!hasStop)
//Statement
.
.
.
@Override
protected void onDestroy() {
super.onDestroy();
hasStop=true;
}
@Override
protected void onResume() {
super.onResume();
hasStop=false;
}
答案 1 :(得分:0)
我认为你应该实施 YourFragment.OnFragmentInteractionListener 在您的活动中,因为片段容器需要上下文和处理程序,上下文是您的活动,处理程序是接口,并且解决了这个问题。
答案 2 :(得分:0)
如果与https://code.google.com/p/android/issues/detail?id=216157
相关I work around this way:
@Override
protected void onDestroy() {
Log.d(TAG, "onDestroy");
try {
super.onDestroy();
} catch (NullPointerException npe) {
Log.e(TAG, "NPE: Bug workaround");
}
答案 3 :(得分:0)
检查您的覆盖方法是否具有正确的超级方法。 我的意思是
@Override
public void onPause() {
super.onPause();
}
应该有super.onPause();只是没有其他方法。
答案 4 :(得分:0)
以防任何未来的人有这个问题....
如果您在onDestroy()
中调用onStop()
,则会抛出无法销毁活动错误
@Override
protected void onStop() {
super.onStop();
onDestroy(); //Don't call this!!!
}
所以请不要在onDestroy()
onStop()
答案 5 :(得分:0)
我有同样的问题。原因是我创建了PagerAdapter,它在保留的Fragment中保存了Context的链接。解决方案 - 重置适配器链接到片段视图重新创建后的上下文。
适配器类:
class TrackingDaysAdapter : PagerAdapter() {
var context: Context? = null
var trackingDays: List<TrackingDay> = emptyList()
set(value) {
field = value
notifyDataSetChanged()
}
override fun instantiateItem(container: ViewGroup, position: Int): Any {
val trackingDayViewImpl = TrackingDayViewImpl(context!!, trackingDays[position].date)
container.addView(trackingDayViewImpl)
return trackingDayViewImpl
}
override fun destroyItem(container: ViewGroup, position: Int, `object`: Any?) {
container.removeView(`object` as View)
}
override fun isViewFromObject(view: View?, `object`: Any?) = view == `object`
override fun getCount() = trackingDays.size
}
和片段类:
class TrackingsFragment : BackStackFragment<TrackingsView, TrackingsPresenter>(), TrackingsView {
@Inject lateinit var adapter: TrackingDaysAdapter
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
adapter.context = context
}
}
答案 6 :(得分:0)
Not a great solution. But You use this until google fixes
@Override
public void finishUpdate(ViewGroup container) {
try{
super.finishUpdate(container);
} catch (NullPointerException nullPointerException){
System.out.println(" NPE in FragmentPagerAdapter.finishUpdate");
}
}