我在 doInBackGround 方法中的 AsyncTask 类中有错误。
从调试我确定程序没有进入 DoInbackGround 方法,在它之前或调用它或传递上下文或活动中存在问题
错误日志:
FATAL EXCEPTION: AsyncTask #3
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:299)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at android.app.SharedPreferencesImpl.getInt(SharedPreferencesImpl.java:221)
at com.app.sams.GetStudentsListAsync.doInBackground(GetStudentsListAsync.java:88)
at com.app.sams.GetStudentsListAsync.doInBackground(GetStudentsListAsync.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:287)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 5 more
调用 AsyncTask
private final List<Teacher> ClassList;
private final Activity activity;
Context context;
public TeacherAdapter(Activity activity, List<Teacher> ClassList,
Context context) {
super(activity, R.layout.activity_list, ClassList);
this.activity = activity;
this.context = context;
this.ClassList = ClassList;
}
holder.Button1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Toast toast = Toast.makeText(context, ClassList.get(position)
.getName(), Toast.LENGTH_LONG);
toast.show();
GetStudentsListAsync asynTask = new GetStudentsListAsync(
activity, context);
asynTask.execute();
}
});
异步任务类:
private Activity activity;
//private ProgressDialog progressDialog;
Context context;
public GetStudentsListAsync(Activity activity, Context context) {
super();
//this.progressDialog = progressDialog;
this.activity = activity;
this.context = context;
}
然后是 DoInBackGround 但我确定上述路线中的问题。