java.lang.NullPointerException when invoking onLoadFinished()

This question already has an answer here:

  • What is a NullPointerException, and how do I fix it? 12 answers
  • NullPointerException in Java when using an object as a field 3 answers

  • Because you are creating ProductCursorAdapter mCursorAdapter within the context of the class but initializing another local variable instead of that one in your onCreate . Here is the problematic line:

    ProductCursorAdapter mCursorAdapter = new ProductCursorAdapter(this, null);

    which should be:

    mCursorAdapter = new ProductCursorAdapter(this, null);


    In onCreate() instead of:

    ProductCursorAdapter mCursorAdapter = new ProductCursorAdapter(this, null);
    

    Do:

    mCursorAdapter = new ProductCursorAdapter(this, null);
    

    You are creating a local variable inside onCreate() , thus the field on your class remains uninitialized.

    链接地址: http://www.djcxy.com/p/32000.html

    上一篇: 关于装饰模式和抽象装饰类的问题?

    下一篇: 调用onLoadFinished()时抛出java.lang.NullPointerException