我在ModelFragment.java中收到以下3个错误:
The method doInBackGround(Context...) of type ModelFragment.PrefsLoadTask must override or implement a supertype method
The type ModelFragment.PrefsLoadTask must implement the inherited abstract method AsyncTask<Context,Void,Void>.doInBackground(Context...)
Void methods cannot return a value
这是我的源代码:
private class PrefsLoadTask extends AsyncTask<Context, Void, Void> {
SharedPreferences localPrefs=null;
@Override
protected void doInBackGround(Context... ctxt) {
localPrefs=PreferenceManager.getDefaultSharedPreferences(ctxt[0]);
localPrefs.getAll();
return(null);
}
@Override
public void onPostExecute(Void Arg0) {
ModelFragment.this.prefs=localPrefs;
ModelFragment.this.prefsTask=null;
deliverModel();
}
}
据我所知,代码就像书中一样。此外,我已经阅读了本章中输入的所有代码。你能看到她的错误吗?应用程序在本章的第5步之后运行正常。
答案 0 :(得分:0)
据我所知,代码与书中的相似
不,不是。它是doInBackground()
,而不是doInBackGround()
(请注意g
的情况)。此外,返回类型必须为Void
,而不是void
(请注意V
的情况。)