Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6066439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:30:03+00:00 2026-05-23T09:30:03+00:00

I have limited the value in this EditText field to numbers, and max length

  • 0

I have limited the value in this EditText field to numbers, and max length of 3

main.xml

    <EditText android:id="@+id/inputTime" android:layout_width="60sp"
    android:layout_height="wrap_content" android:text="@string/inputMaxTime"
    android:textSize="15sp" android:digits="0123456789" android:inputType="numberDecimal" 
    android:numeric="decimal" android:maxLength="3">
</EditText>

I am also, programmatically, limiting the value to be 120, and this is the code:

        final EditText inputMinutes = (EditText) findViewById(R.id.inputTime);

    inputMinutes.setText(String.valueOf(preferences.getLong("neglectedPeriodMsecs", 60000)/60000));

    inputMinutes.addTextChangedListener(new TextWatcher()
    {
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {

        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) 
        {

        }

        @Override
        public void afterTextChanged(Editable s) 
        {
            // TODO Auto-generated method stub
            if(isFreeVersion && Integer.valueOf(inputMinutes.getText().toString()) > 120)
                showToast("The free version is limited to 120 minutes.");
            else
            {
                editor.putLong("neglectedPeriodMsecs", Long.parseLong(s.toString())*60000);
                editor.commit();
            }
        }
    });

I also tried to add another check on the else

else if (Integer.valueOf(inputMinutes.getText().toString()) > 0)
            {
                editor.putLong("neglectedPeriodMsecs", Long.parseLong(s.toString())*60000);
                editor.commit();
            }

no change in the result.

The problem is that when the user deletes ALL the numbers from the view, I get an error. I think I can use a try/catch, but not sure which one, and if that’s the correct way.

Thanks

PFA Logcat
06-27 23:16:00.014: VERBOSE/AlarmManager(2489): set: Alarm{48248e28 type 1 android}
06-27 23:16:42.998: DEBUG/AndroidRuntime(30567): Shutting down VM
06-27 23:16:42.998: WARN/dalvikvm(30567): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): FATAL EXCEPTION: main
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): java.lang.NumberFormatException: unable to parse ” as integer
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at java.lang.Integer.parseInt(Integer.java:412)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at java.lang.Integer.parseInt(Integer.java:382)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at java.lang.Integer.valueOf(Integer.java:682)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.neglected.Neglected$2.afterTextChanged(Neglected.java:120)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.widget.TextView.sendAfterTextChanged(TextView.java:6339)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.widget.TextView$ChangeWatcher.afterTextChanged(TextView.java:6522)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.sendTextHasChanged(SpannableStringBuilder.java:897)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:401)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:269)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:432)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:218)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:28)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:60)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:123)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.text.method.NumberKeyListener.onKeyDown(NumberKeyListener.java:134)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.widget.TextView.doKeyDown(TextView.java:4479)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.widget.TextView.onKeyDown(TextView.java:4324)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.KeyEvent.dispatch(KeyEvent.java:1124)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.View.dispatchKeyEvent(View.java:3740)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:788)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1883)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1154)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.app.Activity.dispatchKeyEvent(Activity.java:2063)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1859)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2495)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.view.ViewRoot.handleMessage(ViewRoot.java:1985)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.os.Looper.loop(Looper.java:123)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at java.lang.reflect.Method.invoke(Method.java:521)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-27 23:16:43.264: ERROR/AndroidRuntime(30567): at dalvik.system.NativeStart.main(Native Method)
06-27 23:16:43.350: WARN/ActivityManager(2489): Process com.neglected has crashed too many times: killing!
06-27 23:16:43.350: WARN/ActivityManager(2489): Force finishing activity com.neglected/.Neglected
06-27 23:16:43.358: INFO/Process(2489): Sending signal. PID: 30567 SIG: 9
06-27 23:16:43.381: INFO/WindowManager(2489): WIN DEATH: Window{47f27e88 com.neglected/com.neglected.Neglected paused=true}
06-27 23:16:53.352: WARN/ActivityManager(2489): Launch timeout has expired, giving up wake lock!

Solution:
Changing the if to:

            public void afterTextChanged(Editable s) 
        {
            String minValueStr = inputMinutes.getText().toString();
            if (minValueStr.length() != 0 ) {
                int minValueInt = Integer.valueOf(minValueStr);
                if(isFreeVersion && minValueInt > FREE_VERSION_MAX_NEGLECTED_TIME)
                {
                    showToast("The free version is limited to " + String.valueOf(FREE_VERSION_MAX_NEGLECTED_TIME) + " minutes.");
                    inputMinutes.setText(String.valueOf(FREE_VERSION_MAX_NEGLECTED_TIME));
                }
                else if (minValueInt > 0)
                {
                    editor.putLong("neglectedPeriodMsecs", Long.parseLong(s.toString())*60000);
                    editor.commit();
                }
            }
        }

thanks for the suggestions. they helped me keep looking.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:30:03+00:00Added an answer on May 23, 2026 at 9:30 am

    Well I would guess that is being caused by a null pointer exception or a exception due to parsing since you are trying to convert the string in the edittext field to a number. So when the user clears the textfield, the code tries to change the null value or empty string into a number which is not possible.

    I am not saying that this is the right answer but this is what I thought after seeing your code.

    You can programatically check to see if the textfield is null and then write the appropriate logic when the textfield is set to null/empty string.

        @Override
        public void afterTextChanged(Editable s) 
        {
          if (inputMinutes.getText != null && !inputMinutes.getText.equals("")) {
            // TODO Auto-generated method stub
            if(isFreeVersion && Integer.valueOf(inputMinutes.getText().toString()) > 120)
                showToast("The free version is limited to 120 minutes.");
            else
            {
                editor.putLong("neglectedPeriodMsecs", Long.parseLong(s.toString())*60000);
                editor.commit();
            }
          }
        }
    

    If it is a nullpointer exception then you can catch that using a try catch block.

    If these are not true then it will be helpful if you post the stacktrace from your logcat which shows the error log so that others can see whats causing this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an jQuery.autocomplete field presenting a limited range of decimal numbers. Ex: var
I am developing an enterprise application for android tablets and i have limited the
I have an input box which is limited to 16 Numbers. What I'd like
I have a boolean variable value stored in an SQL Server database. This is
I have an event stream and a key-val storage. The value size is limited
I have a pretty limited experience with AJAX and javascript so hopefully this is
I have limited experience with .net. My app throws an error this.dateTimeFormat is undefined
For example I have limited space and I want the submit button to appear
As everybody knows, you have limited precision when you use printf to output the
I need some help with PHP Class. I have limited knowledge about how it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.