FacebookからのJSon応答を解析するための次のコードがあります。
doInBackground(JSONObject... params) {
try {
JSONArray posts = params[0].getJSONArray("notifications");
notifications.clear();
for (int i = 0; i < posts.length(); i++) {
Notifications info = new Notifications();
JSONObject tempobj = (JSONObject) posts.get(i);
//some code here related to parse...
}
}catch(Ex...xxx){}
sort();
}
私のソート方法は次のとおりです。
private void sort() {
mActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("sort called", "sort called" + actualListView.getSelectedItemPosition());
try {
Collections.sort(notifications, new Comparator<Notifications>() {
@Override
public int compare(Notifications object1, Notifications object2) {
int time1 = Integer.parseInt(object1.updated_time);
int time2 = Integer.parseInt(object2.updated_time);
if (time1 < time2)
return 1;
else if (time1 > time2)
return -1;
return 0;
}
});
} catch (Exception e) {
Log.e("java.util.Collections", "Error occurred in sorting the notifications");
e.printStackTrace();
}
}
});
}
onPostExecuteメソッドで、UIを更新するために別のメソッドを呼び出します。:しかし、例外に直面しています。ログはここにあります:
STACK_TRACE=java.lang.ExceptionInInitializerError
at
com.platinumapps.fragments.NotificationFragment$NotificationRequestListener.onComplete(NotificationFragment.java:241)
at
com.facebook.android.AsyncFacebookRunner$3.run(AsyncFacebookRunner.java:391)
Caused by: java.lang.RuntimeException: Can't create handler inside thread
that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
... 2 more
java.lang.RuntimeException: Can't create handler inside thread that has not
called Looper.prepare()
at android.os.Handler.<init>(Handler.java:121)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask$InternalHandler.<init>(AsyncTask.java:421)
at android.os.AsyncTask.<clinit>(AsyncTask.java:152)
at
com.platinumapps.fragments.NotificationFragment$NotificationRequestListener.onComplete(NotificationFragment.java:241)
at
com.facebook.android.AsyncFacebookRunner$3.run(AsyncFacebookRunner.java:391)
コードの何が問題になっていますか?私を助けてください。ありがとう。