這裏是我的代碼執行doInBackground時發生錯誤嗎?
package com.example.rollsystems;
import java.util.ArrayList;
import org.dto.Student;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
import android.app.Activity;
import android.content.Context;
import com.example.listview.*;
import com.example.Utils.AllBO;
import com.example.rollsystems.R;
public class RollCallActivity extends Activity {
ArrayList<Student> array;
ListStudentAdapter arrayAdapter;
ListView list;
TextView txtClassAt;
TextView txtSubjectAt;
TextView txtInstructorAt;
TextView txtTimeAt;
TextView txtDateAt;
Context context;
public class RollCallTask extends AsyncTask<Void, Void, Void> {
public RollCallActivity activity;
public RollCallTask(RollCallActivity a)
{
activity = a;
}
@Override
protected Void doInBackground(Void... params) {
//SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("rs", Context.MODE_PRIVATE);
//String RollCallID = sharedPref.getString("RollCallID", "14");
String RollCallID = "14";
list = (ListView)findViewById(R.id.listAtStudent);
ArrayList<Student> rollCalls = new AllBO().getRollCallInfo(RollCallID);
array = rollCalls;
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
arrayAdapter = new ListStudentAdapter(activity, R.layout.list_atstudent, array);
list.setAdapter(arrayAdapter);
txtClassAt = (TextView) findViewById(R.id.txtClassAt);
}
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_rollcall);
new RollCallTask(this).execute();
txtClassAt = (TextView) findViewById(R.id.txtClassAt);
}
}
然後,當我運行:
E/AndroidRuntime(883): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(883): java.lang.RuntimeException: An error occured while executing
doInBackground()
E/AndroidRuntime(883): at android.os.AsyncTask$3.done(AsyncTask.java:278)
每個幫助是珍貴
你能張貼整個logcat的外部內部,所以我們可以看到確切的錯誤 –
把你的doInBackground方法中設置斷點,並通過它一步到找到錯誤。 – Kuffs