我在运行时收到了stacktrace错误。
运行时异常:执行doInBackground()
时发生错误
我发布了完整的堆栈跟踪,并在下面的编码中指出了错误行。
堆栈跟踪:
01-30 05:05:57.213: E/dalvikvm(5676): VM aborting
01-30 05:05:57.213: A/libc(5676): Fatal signal 6 (SIGABRT) at 0x0000162c (code=-6), thread 5676 (e.quranmadeeasy)
01-30 05:05:57.761: D/dalvikvm(5767): GC_FOR_ALLOC freed 121K, 6% free 3345K/3524K, paused 2ms, total 2ms
01-30 05:05:57.761: I/dalvikvm-heap(5767): Grow heap (frag case) to 4.394MB for 1127532-byte allocation
01-30 05:05:57.761: D/dalvikvm(5767): GC_FOR_ALLOC freed <1K, 4% free 4446K/4628K, paused 2ms, total 2ms
01-30 05:05:57.805: W/dalvikvm(5767): threadid=12: thread exiting with uncaught exception (group=0xa4cc6b20)
01-30 05:05:57.805: W/dalvikvm(5767): threadid=15: thread exiting with uncaught exception (group=0xa4cc6b20)
01-30 05:05:57.805: I/Process(5767): Sending signal. PID: 5767 SIG: 9
01-30 05:05:57.805: E/AndroidRuntime(5767): FATAL EXCEPTION: AsyncTask #1
01-30 05:05:57.805: E/AndroidRuntime(5767): Process: com.qrme.quranmadeeasy, PID: 5767
01-30 05:05:57.805: E/AndroidRuntime(5767): java.lang.RuntimeException: An error occured while executing doInBackground()
01-30 05:05:57.805: E/AndroidRuntime(5767): at android.os.AsyncTask$3.done(AsyncTask.java:300)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.FutureTask.run(FutureTask.java:242)
01-30 05:05:57.805: E/AndroidRuntime(5767): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.lang.Thread.run(Thread.java:841)
01-30 05:05:57.805: E/AndroidRuntime(5767): Caused by: java.lang.NullPointerException
01-30 05:05:57.805: E/AndroidRuntime(5767): at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:258)
01-30 05:05:57.805: E/AndroidRuntime(5767): at com.qrme.quranmadeeasy.LessonActivity$getLesson.doInBackground(LessonActivity.java:1)
01-30 05:05:57.805: E/AndroidRuntime(5767): at android.os.AsyncTask$2.call(AsyncTask.java:288)
01-30 05:05:57.805: E/AndroidRuntime(5767): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
01-30 05:05:57.805: E/AndroidRuntime(5767): ... 4 more
LessonActivity.java:
public class LessonActivity extends Activity implements OnItemClickListener {
static ArrayList<Lesson> lessonList =null ;
static ArrayList<Settings> settings = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_lesson);
initialize();
listLesson.setOnItemClickListener(this);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
new getLesson().execute("");
}
..............
..............
// Async Task for getting all lesson of a chapter
public class getLesson extends AsyncTask<String, Void, String> {
// ProgressDialog pd; // progress dialog declaration
@Override
protected String doInBackground(String... params) {
lessonList = DatabaseQueryHelper.getInstance().getLesson(chapterId); -->258th 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);
}
}
}
}
}
任何人都可以帮助我。谢谢。
答案 0 :(得分:0)
在使用lessonList之前,您需要在此行中编写ArrayList<Lesson> lessonList = new ArrayList<Lesson>();
。
答案 1 :(得分:0)
您需要检查没有数据,并且还管理查询以遍历返回的任何数据并将其添加到ArrayList。
我也不确定你为什么要返回null,为什么不把它作为无效返回,如果你没有返回任何有价值的东西?
@Override
protected String doInBackground(String... params) {
try{
lessonList = new ArrayList<String>();
// here you need to get this data and loop through it and add it to your ArrayList
DatabaseQueryHelper.getInstance().getLesson(chapterId);
//create a loop here and go through the data.
lessonList.add("each data");
}catch(NullPointerException e){
//to do
}
return null;// if you are returning null why don't you have a void method?
}