我正在尝试转换
String date = "20130310" 到 android 中的日期格式,我在滚动时遇到异常并崩溃。
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
try {
Date parsed = format.parse(pendingTrade.voteDeadline);
System.out.println(" 2. " + NEWS_DATE_FORMAT.format(parsed));
holder.deadline.setText("Deadline | " + NEWS_DATE_FORMAT.format(parsed));
}
catch(ParseException pe) {
System.out.println("ERROR: Cannot parse \"" + pendingTrade.voteDeadline + "\"");
}
日志是
04-16 13:54:36.410: E/AndroidRuntime(13885): java.lang.NullPointerException
04-16 13:54:36.410: E/AndroidRuntime(13885): at java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1001)
04-16 13:54:36.410: E/AndroidRuntime(13885): at java.text.DateFormat.parse(DateFormat.java:620)
04-16 13:54:36.410: E/AndroidRuntime(13885): at com.cbssports.nflapp.ffb.ui.FragmentPendingTrades$PendingTradesAdapter.getView(FragmentPendingTrades.java:1443)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.AbsListView.obtainView(AbsListView.java:2143)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.ListView.makeAndAddView(ListView.java:1831)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.ListView.fillDown(ListView.java:674)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.ListView.fillGap(ListView.java:638)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4930)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4087)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.view.Choreographer.doFrame(Choreographer.java:531)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.os.Handler.handleCallback(Handler.java:725)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.os.Handler.dispatchMessage(Handler.java:92)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.os.Looper.loop(Looper.java:137)
04-16 13:54:36.410: E/AndroidRuntime(13885): at android.app.ActivityThread.main(ActivityThread.java:5041)
04-16 13:54:36.410: E/AndroidRuntime(13885): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 13:54:36.410: E/AndroidRuntime(13885): at java.lang.reflect.Method.invoke(Method.java:511)
04-16 13:54:36.410: E/AndroidRuntime(13885): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-16 13:54:36.410: E/AndroidRuntime(13885): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-16 13:54:36.410: E/AndroidRuntime(13885): at dalvik.system.NativeStart.main(Native Method)