Asynctask类调用中的错误

时间:2013-09-26 13:32:41

标签: java android android-asynctask

我在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();

    }
});

AsyncTask类:

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,但我确定上述路线中的问题。

1 个答案:

答案 0 :(得分:0)

根据您的日志,问题是因为您在Async任务doInBackgroundMethod中将String值转换为整数。

Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

更准确地说,它看起来像是AsyncTask的以下行号

GetStudentsListAsync.java:88

希望有所帮助。