NullPointerException异常的LoaderManager的restartLoader方法 [英] NullPointerException in restartLoader Method of LoaderManager

查看:289
本文介绍了NullPointerException异常的LoaderManager的restartLoader方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的片段以下自己的接口实现:

I have the following own Interface Implementation in my Fragment:

@Override
    public void onReportChanged(Fragment sender, long id, int position) {
        // Views ein und ausblenden
        _List.setVisibility(View.GONE);
        _OnLoading.setVisibility(View.VISIBLE);
        _NoDataView.setVisibility(View.GONE);
        _ReportId = id;
        getLoaderManager().restartLoader(_LM_REPORTS, null, this);
    };

该FragmentActivity报告这个片段,另一个片段(选择列表)选择一个项目。在此之后,ListFragment应加载新的数据与报告的ID(_ReportId)。

The FragmentActivity report to this Fragment, that another Fragment (Selection List) have selected one item. After that the ListFragment should load new Data with reported ID (_ReportId).

不过,我得到 NullPoinerException 这个code才去onCreateLoader法。这里是LogCat中:

But I get NullPoinerException on this code before going to onCreateLoader-Method. Here is the LogCat:

05-28 14:24:37.905: E/AndroidRuntime(1775): FATAL EXCEPTION: main
05-28 14:24:37.905: E/AndroidRuntime(1775): java.lang.NullPointerException
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.support.v4.app.LoaderManagerImpl.restartLoader(LoaderManager.java:637)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at de.webducer.android.worktime.beta.ui.fragment.ReportListFragment.onReportChanged(ReportListFra gment.java:142)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at de.webducer.android.worktime.beta.ui.ReportListActivity.onReportSelected(ReportListActivity.java:97)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at de.webducer.android.worktime.beta.ui.fragment.ReportSelectorSpinnerFragment$1.onItemSelected(ReportSelectorSpinnerFragment.java:78)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.widget.AdapterView.fireOnSelected(AdapterView.java:882)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.widget.AdapterView.access$200(AdapterView.java:48)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:848)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.os.Handler.handleCallback(Handler.java:605)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.os.Looper.loop(Looper.java:137)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at android.app.ActivityThread.main(ActivityThread.java:4424)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at java.lang.reflect.Method.invokeNative(Native Method)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at java.lang.reflect.Method.invoke(Method.java:511)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-28 14:24:37.905: E/AndroidRuntime(1775):     at dalvik.system.NativeStart.main(Native Method)

我不明白为什么。同样的code(但对于其他列表)正常工作的其他FragmentActivity。

I don'T understand why. The same code (but for the other list) works fine on the other FragmentActivity.

推荐答案

我找到了原因:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle extra) {
    CursorLoader returnValue = null;
    if (_ReportId > 0) {
        switch (id) {
            case _LM_REPORTS:
                returnValue = new CursorLoader(getActivity(),
                    ReportContentProvider.CONTENT_URI_REPORT_DATA,
                    null,
                    ReportTable.COLUMN_ID + " =?",
                    new String[] { String.valueOf(_ReportId) },
                    null);
                    break;

                default:
                    break;
            }
        }
    return returnValue;
}

装载程序有百达运行。条件如果(_ReportId→1)产生的异常。如果没有条件code运行正常。

The Loader have allways to run. The condition if (_ReportId > 1) produced the exception. Without the condition the code runs fine.

这篇关于NullPointerException异常的LoaderManager的restartLoader方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆