ネットワーク指向のタスクを実行するために、その中にFragment
入れて使用しています。AsyncTask
すべて正常に動作します。向きをプロトレイトからランドスケープに変更すると、うまくいきません。しかし、方向を再度 に変更するとportrait
、クラッシュします。これは私の試行コードです。
public class ProblemStatistics extends SherlockProgressFragment {
View mContentView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContentView = inflater.inflate(R.layout.submission_statistics,
container, false);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setContentShown(false);
setContentView(mContentView);
Bundle bundle = this.getArguments();
int problemNo = 100;
if (bundle != null) {
problemNo = bundle.getInt("problem_no", problemNo);
}
new GetProblemStatisticTask().execute(CommonUtils.SPECIFIC_PROBLEM_URL + problemNo);
}
@Override
public void onStop() {
((MainActivity) getSherlockActivity()).setProblemStatistics(false);
super.onStop();
}
protected class GetProblemStatisticTask extends
AsyncTask<String, Void, InputStreamReader> {
@Override
protected InputStreamReader doInBackground(String... params) {
return new JSONDownloader().getJSONStringFromUrl(params[0]);
}
@Override
protected void onPostExecute(InputStreamReader isr) {
super.onPostExecute(isr);
// other stuff and parsing related code
layout.addView(gView);
setContentShown(true);
}
}
}
そして、これは私のエラーログです:
08-16 00:07:18.025: E/AndroidRuntime(542): java.lang.NullPointerException
08-16 00:07:18.025: E/AndroidRuntime(542): at me.kaidul.uhunt.LatestSubmissions$GetSubmissionsListTask.onPostExecute(LatestSubmissions.java:84)
08-16 00:07:18.025: E/AndroidRuntime(542): at me.kaidul.uhunt.LatestSubmissions$GetSubmissionsListTask.onPostExecute(LatestSubmissions.java:1)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.os.AsyncTask.finish(AsyncTask.java:417)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.os.AsyncTask.access$300(AsyncTask.java:127)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.os.Looper.loop(Looper.java:123)
08-16 00:07:18.025: E/AndroidRuntime(542): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-16 00:07:18.025: E/AndroidRuntime(542): at java.lang.reflect.Method.invokeNative(Native Method)
08-16 00:07:18.025: E/AndroidRuntime(542): at java.lang.reflect.Method.invoke(Method.java:521)
08-16 00:07:18.025: E/AndroidRuntime(542): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-16 00:07:18.025: E/AndroidRuntime(542): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-16 00:07:18.025: E/AndroidRuntime(542): at dalvik.system.NativeStart.main(Native Method)