程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-20130310字符串轉換

android-20130310字符串轉換

編輯:編程綜合問答
20130310字符串轉換

想要轉換字符串日期=20130310到日期格式。

在安卓中運行之後給我報出了異常。並且在滾動時就崩潰。

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)

最佳回答:


你獲得的異常是NullPointerException
檢查一下pendingTrade.voteDeadline的值,可能是空值引起的。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved