android – java.lang.NumberFormatException: For input string: “5.3”

when running this code i am getting this java.lang.NumberFormatException: For input string: “5.3” Exception. how can we resolve this type of exception and what’s the reason for this type of exception.please explain.please find the code below.

package com.pds.ftp.view.activity;

import android.content.res.Configuration;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.pds.ftp.R;
import com.pds.ftp.app.FTPApp;
import com.pds.ftp.constant.UIConstant;
import com.pds.ftp.infrastructure.ReaderUsbInterf;
import com.pds.ftp.middleware.FTPPrivilegedServiceProvider;
import com.pds.ftp.middleware.PollingLooperThread;
import com.pds.ftp.middleware.ShutDownManager;
import com.pds.ftp.model.dbsync.DBSynchronizationPool;
import com.pds.ftp.transaction.shutdown.EntryExitCheck;
import com.pds.ftp.transaction.shutdown.ShutdownStateCache;
import com.pds.ftp.utils.Util;
import com.pds.hardwareadapter.ingenicoreader.IngenicoReaderDirect;
import com.pds.infrastructure.constants.PreferenceConstants;
import com.pds.infrastructure.interfaces.ILogOperation;
import com.pds.infrastructure.logger.LogCriticalEvent;
import com.pds.infrastructure.logger.LogInfoEvent;
import com.pds.infrastructure.logger.LogWarningEvent;

import javax.inject.Inject;

public class PowerOffActivity extends BaseActivity {

    public static final String TYPE = "action_type";
    public static final int TYPE_SHUTDOWN = 0;
    public static final int TYPE_RESTART = 1;
    public static final int TYPE_END_OF_BUSINESS_HOURS = 2;
    public static final int SHUTDOWN_DELAY = 1000 * 30;
    public static final int SHUTDOWN_WAIT = 1000;
    public static final int READER_REBOOT = 3;

    @Inject
    ILogOperation logOperation;

    @Inject
    EntryExitCheck entryExitCheck;

    @Inject
    ShutdownStateCache shutdownStateCache;

    @Inject
    IngenicoReaderDirect ingenicoReaderDirect;

    @Inject
    PollingLooperThread pollingLooperThread;

    @Inject
    ReaderUsbInterf usbInterf;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        isShutDownRequestInitiated = true;
        setContentView(R.layout.activity_power_off);

        shutdownStateCache.setShutdownState(true); //Shutdown state is true as power is disconnected
        logOperation.logInfo(LogInfoEvent.GENERAL_INFO, "PowerOff Screen Started");

    }

    boolean keepOnRunning = true;

    private void checkForPendingTaskBeforeShutdown() {
        keepOnRunning = true;
        long startTime = System.currentTimeMillis();
        new Thread(new Runnable() {
            @Override
            public void run() {
                pollingLooperThread.onpause();
                if (getIntent() != null) {
                    int type = getIntent().getIntExtra(TYPE, 0);
                    int currentErrorCode = Integer.parseInt(configParams.getString(PreferenceConstants.DEVICE_LAST_ERROR_CODE));
                    int restartCount = configParams.getInt(PreferenceConstants.PREF_FTP_RESTART_COUNT);
                    if (type == TYPE_END_OF_BUSINESS_HOURS || (currentErrorCode == LogCriticalEvent.CARD_READER_MALFUNCTION && restartCount == 1)) {
                        logOperation.logInfo(LogInfoEvent.GENERAL_INFO, "Calling reader reset command due to EOB or CARD_READER_MALFUNCTION. currentErrorCode:: "+currentErrorCode);
                        try {
                            Thread.sleep(3500);
                        } catch (Exception e) {
                            logOperation.logVerbose(LogInfoEvent.GENERAL_INFO, e,"Exception caused in Thread.sleep during reset reader");
                        }
                        ingenicoReaderDirect.resetReader();
                    }
                } else{
                    logOperation.logInfo(LogInfoEvent.GENERAL_INFO, "getIntent() is null");
                }

                while (keepOnRunning) {

                    if (entryExitCheck.getShutDownDBTaskCounter() == 0) {
                        logOperation.logVerbose(LogInfoEvent.GENERAL_INFO, "All threads are completed");
                        keepOnRunning = false;
                    } else {
                        if ((System.currentTimeMillis() - startTime) >= SHUTDOWN_DELAY) {
                            logOperation.logVerbose(LogInfoEvent.GENERAL_INFO, "Time exceeds 30 sec,initiating shutdown");
                            keepOnRunning = false;
                        } else {
                            logOperation.logVerbose(LogInfoEvent.GENERAL_INFO, "Threads still running");
                        }
                    }
                    try {
                        Thread.sleep(SHUTDOWN_WAIT);
                    } catch (Exception e) {
                        logOperation.logInfo(LogInfoEvent.GENERAL_INFO,e,"checkForPendingTaskBeforeShutdown Exception");
                    }
                }

                performShutdownProcess();
            }
        }).start();
    }

    @Override
    protected void onResume() {
        super.onResume();
        checkForPendingTaskBeforeShutdown();
    }

    private void performShutdownProcess() {
        if (!Util.shutdown_file_available()) {
            FTPApp.isShuttingDownState = true;
            Util.setLastShutDownDateTime(configParams);
            if (getIntent() != null) {
                int type = getIntent().getIntExtra(TYPE, 0);
                String state = getIntent().getStringExtra(UIConstant.UISTATE);

                if (type == TYPE_END_OF_BUSINESS_HOURS) {
                    logOperation.logWarning(LogWarningEvent.DEVICE_SCHEDULED_OUT_OF_SERVICE, 2, "Device restarting because of end of business hours");
                }

                /*if (state.contains(UIConstant.IGNITION_OFF)) {
                    FTPApp.isShuttingDownState = true;
                }*/

                if (type == TYPE_RESTART || type == TYPE_END_OF_BUSINESS_HOURS|| type == READER_REBOOT) {
                    logOperation.logWarning(LogWarningEvent.DEVICE_REBOOTED, "Device is RESTARTING.. Coming from:- " + state);
                } else {
                    logOperation.logWarning(LogWarningEvent.DEVICE_SHUT_DOWN, "Device is shutting down Reason:- IGNITION... Coming From:- " + state);
                }
            } else {
                logOperation.logWarning(LogWarningEvent.DEVICE_REBOOTED, "Device is RESTARTING. Reason:- OTHER");
            }
            usbInterf.close();
            ShutDownManager.getInstance().shutDownDevice();
        }
    }

    @Override
    void prepareTextToSpeechAndSpeak() {
    }


    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

    }
}

getting this in logs it looks like this exception is coming from line 79

4,0,05.16.2022_09.09.00.822,java.lang.NumberFormatException: For input string: "5.3"
java.lang.Integer.parseInt(Integer.java:608)
java.lang.Integer.parseInt(Integer.java:643)
com.pds.ftp.view.activity.PowerOffActivity$1.run(PowerOffActivity.java:79)
java.lang.Thread.run(Thread.java:764)
Line 8922: 2,1000,05.16.2022_09.09.00.910,Info,Current Error Code = 0

Leave a Comment