Niraj Niraj - 10 months ago 49
Android Question

How to make condtiion if string not equal to null and greater than equal to 10 and less than equal to 1000?

I have an app which contain edit text in which user enter amount and i have to make condition if amount not equal to null and must be greater than equal to 10 and less that equals to 1000. But i am getting error.

code:-

if (!hasFocus) {
if (m_szAmount.length()==0 && Integer.parseInt(m_szAmount) < 10 && Integer.parseInt(m_szAmount) > 1000) {
m_InputPointsLayout.setErrorEnabled(true);
m_InputPointsLayout.setError(getResources().getString(R.string.enter_points_error));
} else {
m_InputPointsLayout.setErrorEnabled(false);
m_InputPointsLayout.setError(null);
}
}


Caused by: java.lang.NumberFormatException: Invalid int: ""

Answer Source

Change your if statement. Your question says you want to check condition 1 and 2 and 3 but you have done is OR(||)

if ((m_szAmount.length()!=0 && Integer.parseInt(m_szAmount)>=10 && Integer.parseInt(m_szAmount)<=1000) && (m_operatorSpinner.getSelectedItemPosition() > 0 && m_circleSpinner.getSelectedItemPosition() > 0)) {
        m_SubmitButton.setEnabled(true);
    }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download