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 8693675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:35:57+00:00 2026-06-13T00:35:57+00:00

When I try to run the code below, my program has stops. I want

  • 0

When I try to run the code below, my program has stops. I want this code to get the value from edittext but it´s not working as I expected it. What am I doing wrong?

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button sum = (Button) findViewById(R.id.button1);
    Button cancel = (Button) findViewById(R.id.button2);

    final EditText from = (EditText) findViewById(R.id.editText1);
    final EditText upto = (EditText) findViewById(R.id.editText2);
    final EditText runsum = (EditText) findViewById(R.id.editText3);

    final int f = Integer.parseInt(from.getText().toString());
    final int u = Integer.parseInt(upto.getText().toString());

}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

Here is my LogCat sorry for mess :/

08-28 19:34:44.241: E/Trace(3346): error opening trace file: No such file or directory (2)
08-28 19:34:44.780: D/AndroidRuntime(3346): Shutting down VM
08-28 19:34:44.780: W/dalvikvm(3346): threadid=1: thread exiting with uncaught exception(group=0x40a13300)
08-28 19:34:44.790: E/AndroidRuntime(3346): FATAL EXCEPTION: main
08-28 19:34:44.790: E/AndroidRuntime(3346): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.project/com.example.project.MainActivity}: java.lang.NumberFormatException: Invalid int: ""
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread.access$600(ActivityThread.java:130)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.os.Looper.loop(Looper.java:137)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at java.lang.reflect.Method.invokeNative(Native Method)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at java.lang.reflect.Method.invoke(Method.java:511)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at dalvik.system.NativeStart.main(Native Method)
08-28 19:34:44.790: E/AndroidRuntime(3346): Caused by: java.lang.NumberFormatException: Invalid int: ""
08-28 19:34:44.790: E/AndroidRuntime(3346):     at java.lang.Integer.invalidInt(Integer.java:138)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at java.lang.Integer.parseInt(Integer.java:359)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at java.lang.Integer.parseInt(Integer.java:332)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at com.example.project.MainActivity.onCreate(MainActivity.java:25)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.Activity.performCreate(Activity.java:5008)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
08-28 19:34:44.790: E/AndroidRuntime(3346):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
08-28 19:34:44.790: E/AndroidRuntime(3346):     ... 11 more
08-28 19:35:10.560: E/Trace(3394): error opening trace file: No such file or directory (2)
08-28 19:35:11.629: D/gralloc_goldfish(3394): Emulator without GPU emulation detected.
08-28 19:48:19.295: I/Choreographer(3394): Skipped 41 frames!  The application may be doing too much work on its main thread.
  • 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-06-13T00:35:58+00:00Added an answer on June 13, 2026 at 12:35 am

    The problem seems that when Activity is bringed to front there is no value in EditText. Integer parser don’t know how to parse empty String, so Exception is thrown.

    You need to check for existing of text in that EditText before parsing

    final int f = -1; // or other invalid value
    if (from.getText().toString().length() > 0)
        f = Integer.parseInt(from.getText().toString());
    

    Similarly for other EditText

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

Sidebar

Related Questions

This Java code compiles fine, but when I try to run it I get:
When I try to run this code, I get incorrect maximums and minimums. Could
When I run the code below it removes deleted_partner from B . But as
When I try to run my code on any other webbrowsers apart from the
When I try to run the following code from the REPL (playing with dynamic
When I try to run a routine I get the following error: Error Code:
I have the given view and template code, when i try to run this
Thanks in advance. This is my sample code. Whenever i try to run it
My code does not run when the DataReader is empty. Below is my code.
I'm getting this exception when I try to run this program. It's one of

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.