启动ACRA导致排球的其他问题,可能的修复?

时间:2016-03-06 18:47:16

标签: java android android-volley acra

我正在使用Volley进行网络通话!此外,我使用LRU缓存来缓存图像并使用齐射自己的NetworkImageView进行填充。到目前为止一切正常!然而,当我在我的Application类中调用初始ACRA(Crash reporter)时,Volley正在创建NullPointerException。我绝对不知道在哪里寻找这个bug。 这是我的Application类的代码。

AppController.class

    @ReportsCrashes()

public class AppController extends Application
{
    public static final String TAG = AppController.class.getSimpleName();

    private RequestQueue mRequestQueue;
    private ImageLoader mImageLoader;



    private static AppController mInstance;

    @Override
    public void onCreate() {
        super.onCreate();
        ACRA.init(this);

    }

    public static synchronized AppController getInstance() {
        return mInstance;
    }

    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }

        return mRequestQueue;
    }

    public ImageLoader getImageLoader() {
        getRequestQueue();
        if (mImageLoader == null) {
            mImageLoader = new ImageLoader(this.mRequestQueue,
                    new LruBitmapCache());
        }
        return this.mImageLoader;
    }

    public <T> void addToRequestQueue(Request<T> req, String tag) {
        // set the default tag if tag is empty
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        getRequestQueue().add(req);
    }

    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }

    public void cancelPendingRequests(Object tag) {
        if (mRequestQueue != null) {
            mRequestQueue.cancelAll(tag);
        }
    }
}

我的RecyclerView的适配器中抛出了异常,其中我填充了缓存的项目。

CustomAdapter.class

ImageLoader imageLoader = AppController.getInstance().getImageLoader();
ImageLoader imageLoader2 = AppController.getInstance().getImageLoader();

logcat输出为:

  

E / AndroidRuntime:致命异常:主要                                                      过程:com.mobloo.eduknow,PID:28295                                                      java.lang.NullPointerException:尝试调用虚方法   &#39; com.android.volley.toolbox.ImageLoader   com.mobloo.eduknow.AppController.getImageLoader()&#39;在null对象上   参考                                                          在com.mobloo.eduknow.CustomAdapter。(CustomAdapter.java:33)                                                          在com.mobloo.eduknow.FeedsFragment.onCreateView(FeedsFragment.java:57)                                                          在android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)                                                          在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)                                                          在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)                                                          在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)                                                          在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)                                                          在android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)                                                          在android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)                                                          在android.support.v4.view.ViewPager.populate(ViewPager.java:1106)                                                          在android.support.v4.view.ViewPager.populate(ViewPager.java:952)                                                          在android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)                                                          在android.view.View.measure(View.java:18794)                                                          在android.widget.RelativeLayout.measureChildHorizo​​ntal(RelativeLayout.java:715)                                                          在android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)                                                          在android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)                                                          在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)                                                          在android.widget.LinearLayout.measureVertical(LinearLayout.java:748)                                                          在android.widget.LinearLayout.onMeasure(LinearLayout.java:630)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)                                                          在android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)                                                          在android.widget.LinearLayout.measureVertical(LinearLayout.java:748)                                                          在android.widget.LinearLayout.onMeasure(LinearLayout.java:630)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)                                                          在android.widget.FrameLayout.onMeasure(FrameLayout.java:194)                                                          在com.android.internal.policy.PhoneWindow $ DecorView.onMeasure(PhoneWindow.java:2643)                                                          在android.view.View.measure(View.java:18794)                                                          在android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)                                                          在android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)                                                          在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)                                                          在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)                                                          在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6013)                                                          在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:858)                                                          在android.view.Choreographer.doCallbacks(Choreographer.java:670)                                                          在android.view.Choreographer.doFrame(Choreographer.java:606)                                                          在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:844)                                                          在android.os.Handler.handleCallback(Handler.java:739)                                                          在android.os.Handler.dispatchMessage(Handler.java:95)                                                          在android.os.Looper.loop(Looper.java:148)                                                          在android.app.ActivityThread.main(ActivityThread.java:5417)                                                          at java.lang.reflect.Method.invoke(Native Method)                                                          在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:726)                                                          在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

ACRA初始化是否会影响Volley,以便Volley没有正确启动以抛出NullPointerException?可以解决这个问题的原因是什么?

1 个答案:

答案 0 :(得分:2)

mInstancenull,因为您从不为其分配值。这与ACRA无关,除非您在ACRA中添加时意外删除了一些代码。