空指针异常:执行doInBackground()时发生错误:应用程序崩溃

时间:2015-02-02 08:19:32

标签: java android nullpointerexception

我收到以下运行时异常。

Fatal signal 6 (SIGABRT) at 0x00000820 (code=-6), thread 2080
thread eixiting with uncaught exception
java.lang.RuntimeException: An error occured while executing doInBackground()

我发布了以下完整的堆栈跟踪错误:

堆栈跟踪:

02-02 02:13:17.137: E/dalvikvm(2080): VM aborting
02-02 02:13:17.137: A/libc(2080): Fatal signal 6 (SIGABRT) at 0x00000820 (code=-6), thread 2080 (e.quranmadeeasy)
02-02 02:13:20.177: D/dalvikvm(2140): GC_FOR_ALLOC freed 101K, 8% free 2981K/3208K, paused 74ms, total 75ms
02-02 02:13:20.177: I/dalvikvm-heap(2140): Grow heap (frag case) to 3.637MB for 635812-byte allocation
02-02 02:13:20.217: D/dalvikvm(2140): GC_FOR_ALLOC freed 0K, 6% free 3602K/3832K, paused 36ms, total 36ms
02-02 02:13:20.397: W/dalvikvm(2140): threadid=13: thread exiting with uncaught exception (group=0xb3a3cba8)
02-02 02:13:20.397: E/AndroidRuntime(2140): FATAL EXCEPTION: AsyncTask #1
02-02 02:13:20.397: E/AndroidRuntime(2140): Process: com.qrme.quranmadeeasy, PID: 2140
02-02 02:13:20.397: E/AndroidRuntime(2140): java.lang.RuntimeException: An error occured while executing doInBackground()
02-02 02:13:20.397: E/AndroidRuntime(2140):     at android.os.AsyncTask$3.done(AsyncTask.java:300)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.FutureTask.run(FutureTask.java:242)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.lang.Thread.run(Thread.java:841)
02-02 02:13:20.397: E/AndroidRuntime(2140): Caused by: java.lang.NullPointerException
02-02 02:13:20.397: E/AndroidRuntime(2140):     at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:259)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:1)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
02-02 02:13:20.397: E/AndroidRuntime(2140):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-02 02:13:20.397: E/AndroidRuntime(2140):     ... 4 more

我在下面的代码中指出了错误行。

LessonActivity.java:

public class LessonActivity extends Activity implements OnItemClickListener {

AdapterLesson al; // creating object of AdapterLesson class
    static ArrayList<Lesson> lessonList = null;
    static ArrayList<Settings> settings = null;
    int chapterId;
AdapterPages adapPage;
static ArrayList<Page> selectedpageList = null;
    static ArrayList<Page> pageList = null;

@Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        setContentView(R.layout.activity_lesson);
        ParseAnalytics.trackAppOpened(getIntent());
        if (getIntent() != null && getIntent().getExtras() != null) {
            String chapt_id = getIntent().getExtras().getString("CHAPTER_ID");
            chapter = getIntent().getExtras().getString("CHAPTER_NAME");
            // txtChapterdetails.setText(chapter);
            if (chapt_id != null && !chapt_id.equalsIgnoreCase("")) {
                chapterId = Integer.parseInt(chapt_id);
            }
        }
        initialize();
        listLesson.setOnItemClickListener(this);
    }


    public class getLesson extends AsyncTask<String, Void, String> {


        @Override
        protected String doInBackground(String... params) {


            lessonList = DatabaseQueryHelper.getInstance().getLesson(chapterId);  --->259th line

            return null;
        }  

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

        }

        @Override
        protected void onPostExecute(String result) {

            if(lessonList!=null)
            {
                if(lessonList.size()>0)
                {
            al = new AdapterLesson(LessonActivity.this, lessonList); 
            listLesson.setAdapter(al); 
            }
            }
        }
    }
}

任何人都可以帮助我。谢谢。

1 个答案:

答案 0 :(得分:1)

问题出在DatabaseQueryHelper课程中。在初始化实例之前调用方法getInstance()。因此,当您调用它时,您将获得NullPointerException。查找ways to implement a Singleton以便更正此问题。