jsonデータを取得し、arrylistに日付とnulldateストアを取得したい。以下のlistviewsortdateで日付とnull日付データセットを並べ替える方法。All_Approval_data_dtoクラスのすべてのデータに保存します。以下に示す私のコード:それをチェックしてください、そして私がそれを逃しているものは何ですか?
static final Comparator<All_Approval_data_dto> byDate = new Comparator<All_Approval_data_dto>() {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
public int compare(All_Approval_data_dto ord1,
All_Approval_data_dto ord2) {
java.util.Date d1 = null;
java.util.Date d2 = null;
try {
d1 = sdf.parse(ord1.lastModifiedDate);
d2 = sdf.parse(ord2.lastModifiedDate);
if (d1 == null) {
return (d2 == null) ? 0 : -1;
}
if (d2 == null) {
return 1;
}
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block`
e.printStackTrace();
}
return (d1.getTime() > d2.getTime() ? -1 : 1); // descending
// return (d1.getTime() > d2.getTime() ? 1 : -1); //ascending
}
};
以下の私のエラー:
11-02 11:03:58.861: ERROR/AndroidRuntime(473): FATAL EXCEPTION: main
11-02 11:03:58.861: ERROR/AndroidRuntime(473): java.lang.NullPointerException
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1201)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.text.DateFormat.parse(DateFormat.java:642)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at com.serana.Approval$2.compare(Approval.java:155)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at com.serana.Approval$2.compare(Approval.java:1)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.util.TimSort.countRunAndMakeAscending(TimSort.java:320)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.util.TimSort.sort(TimSort.java:185)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.util.TimSort.sort(TimSort.java:169)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.util.Arrays.sort(Arrays.java:1907)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.util.Collections.sort(Collections.java:1972)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at com.serana.Approval$4.onItemSelected(Approval.java:79)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.widget.AdapterView.fireOnSelected(AdapterView.java:864)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.widget.AdapterView.access$200(AdapterView.java:42)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.widget.AdapterView$SelectionNotifier.run(AdapterView.java:830)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.os.Handler.handleCallback(Handler.java:587)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.os.Handler.dispatchMessage(Handler.java:92)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.os.Looper.loop(Looper.java:123)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at java.lang.reflect.Method.invoke(Method.java:521)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-02 11:03:58.861: ERROR/AndroidRuntime(473): at dalvik.system.NativeStart.main(Native Method)