java.lang.NumberFormatException:对于输入字符串:“ 21:30”

时间:2018-09-28 23:16:44

标签: java android numberformatexception

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.dmc.carambola.performa, PID: 9971
              java.lang.NumberFormatException: For input string: "21:30"
                  at java.lang.Integer.parseInt(Integer.java:608)
                  at java.lang.Integer.parseInt(Integer.java:643)
                  at com.dmc.carambola.performa.Adapters.AirDetailsAdapter.onBindViewHolder(AirDetailsAdapter.java:93)
                  at com.dmc.carambola.performa.Adapters.AirDetailsAdapter.onBindViewHolder(AirDetailsAdapter.java:29)
                  at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6482)
                  at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6515)
                  at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5458)
                  at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5724)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
                  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
                  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
                  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
                  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
                  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3693)
                  at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3410)
                  at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3962)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
                  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
                  at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791)
                  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635)
                  at android.widget.LinearLayout.onLayout(LinearLayout.java:1544)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)
                  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
                  at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
                  at com.android.internal.policy.DecorView.onLayout(DecorView.java:758)
                  at android.view.View.layout(View.java:19590)
                  at android.view.ViewGroup.layout(ViewGroup.java:6053)

E / AndroidRuntime:位于android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2484)                       在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2200)                       在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)                       在android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:6733)                       在android.view.Choreographer $ CallbackRecord.run(Choreographer.java:911)                       在android.view.Choreographer.doCallbacks(Choreographer.java:723)                       在android.view.Choreographer.doFrame(Choreographer.java:658)                       在android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:897)                       在android.os.Handler.handleCallback(Handler.java:789)                       在android.os.Handler.dispatchMessage(Handler.java:98)                       在android.os.Looper.loop(Looper.java:164)                       在android.app.ActivityThread.main(ActivityThread.java:6541)                       在java.lang.reflect.Method.invoke(本机方法)                       在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240)                       在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

            if(selectedFlight.getRoutePoints().size() > position) {
            final RoutePoint nextRoutePoint = selectedFlight.getRoutePoints().get(position);

            String departureHour = nextRoutePoint.getDepartureTime();
            String departureHourConverted = DateHelper.formatter(departureHour, "HH:mm");
            int departure = Integer.parseInt(departureHourConverted.toString()); //This is line 93

            String arrivalTimeHour = currentRoutePoint.getDestinationArrivalTime();
            String arrivalTimeHourConverted = DateHelper.formatter(arrivalTimeHour, "HH:mm");
            int arrivalTime = Integer.parseInt(arrivalTimeHourConverted.toString());

            int time = departure - arrivalTime;

            // SE nextRoutePoint.departure - current.arrivalTime <= 24h
            if (time <= 1000 * 60 * 60 * 24) {
                // Exibe este valor em String.parseString("Tempo de conexão: %d", tempo)
                Integer minutes = (time % (1000 * 60 * 60)) / (1000 * 60);
                Integer hours =  (time % (1000 * 60 * 60 * 24) / (1000 + 60 + 60));
                String content = String.format("Tempo de conexão: %d:%02d", hours, minutes);
                holder.time_connection.setText(content);

            }

我需要将字符串“ HH:mm”转换为int

1 个答案:

答案 0 :(得分:0)

由于它不是整数,因此不会解析“:”字符。这就是为什么它抛出数字格式异常的原因,因为它不是数字