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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:11:33+00:00 2026-06-08T21:11:33+00:00

I have an activity with 3 EditTexts and Button. User can fill two edittexts

  • 0

I have an activity with 3 EditTexts and Button. User can fill two edittexts (edittext 1 and 2 or 1 and 3). Always one edit text (2nd or 3rd) must be empty. After click button shows the correct results. I dont know how to change my code. If I have empty edittext the application has stopped unexpectly. If I insert value 0 to no use edittext everythings are ok. Has anyone got any ideas? How to solve this problem? Thanks a lot for help.
this is my main activity code:

   public class Glowna extends Activity implements OnClickListener{


@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View button1Button = this.findViewById(R.id.oblicz);
button1Button.setOnClickListener(this);             
} 
public void onClick(View v){ 
EditText numa = (EditText)findViewById(R.id.a); 
EditText numb = (EditText)findViewById(R.id.b); 
EditText numc = (EditText)findViewById(R.id.c); 
float eq1 = 0; 
float eq2 = 0; 
float eq3 = 0; 
float eq4 = 0; 
float num1 = Float.parseFloat(numa.getText().toString()); 
float num2 = Float.parseFloat(numb.getText().toString()); 
float num3 = Float.parseFloat(numc.getText().toString());


if (num1>0 & num2>0){
try{
switch (v.getId()) {
    case R.id.oblicz:
    eq1 = 4*num1;
    eq2 = num1*num2;
    break;  }
String wynik1 = Float.toString(eq1);
String wynik2 = Float.toString(eq2);
 Intent i = new Intent(this, Wynik.class);
 i.putExtra("a",wynik1);
 i.putExtra("b",wynik2);
startActivity(i); }

catch (NumberFormatException e) {Intent o = new Intent(this, Komunikat.class);
startActivity(o); return; }}


else if (num1>0&num3>0){
try{
switch (v.getId()) {
case R.id.oblicz:
eq4 = 4*num1;
eq3 = (num3/2)*num3;
break;  }
String wynik4 = Float.toString(eq4);
String wynik3 = Float.toString(eq3);
Intent j = new Intent(this, Wynik1.class);
j.putExtra("d",wynik4);
j.putExtra("c",wynik3);
startActivity(j); }
catch (NumberFormatException e) {Intent o = new Intent(this, Komunikat.class);
startActivity(o);
return;}}      

else {Intent o = new Intent(this, Komunikat.class);
startActivity(o);}  

}}

and errors:

E/AndroidRuntime(249): Uncaught handler: thread main exiting due to uncaught exception

 E/AndroidRuntime(249): java.lang.NumberFormatException: 

 E/AndroidRuntime(249):     at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:296)

 E/AndroidRuntime(249):     at java.lang.Float.parseFloat(Float.java:327)

 E/AndroidRuntime(249):     at arek.gemetrytesty.glowna.Glowna.onClick(Glowna.java:38)

 E/AndroidRuntime(249):     at android.view.View.performClick(View.java:2344)

 E/AndroidRuntime(249):     at android.view.View.onTouchEvent(View.java:4133)

 E/AndroidRuntime(249):     at android.widget.TextView.onTouchEvent(TextView.java:6510)

 E/AndroidRuntime(249):     at android.view.View.dispatchTouchEvent(View.java:3672)

 E/AndroidRuntime(249):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

 E/AndroidRuntime(249):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

 E/AndroidRuntime(249):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

 E/AndroidRuntime(249):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)

 E/AndroidRuntime(249):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)

 E/AndroidRuntime(249):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)

 E/AndroidRuntime(249):     at android.app.Activity.dispatchTouchEvent(Activity.java:1987)

 E/AndroidRuntime(249):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)

 E/AndroidRuntime(249):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)

 E/AndroidRuntime(249):     at android.os.Handler.dispatchMessage(Handler.java:99)

 E/AndroidRuntime(249):     at android.os.Looper.loop(Looper.java:123)

 E/AndroidRuntime(249):     at android.app.ActivityThread.main(ActivityThread.java:4203)

 E/AndroidRuntime(249):     at java.lang.reflect.Method.invokeNative(Native Method)

 E/AndroidRuntime(249):     at java.lang.reflect.Method.invoke(Method.java:521)
 E/AndroidRuntime(249):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)

 E/AndroidRuntime(249):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)

 E/AndroidRuntime(249):     at dalvik.system.NativeStart.main(Native Method)
  • 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-08T21:11:34+00:00Added an answer on June 8, 2026 at 9:11 pm

    To catch java.lang.NumberFormatException,try this:

    float num1 = Float.parseFloat(numa.getText().toString());
            float num2;
            float num3;
            try {
                num2 = Float.parseFloat(numb.getText().toString());
            } catch (Exception e) {
                num2 = 0;
            }
            try {
                num3 = Float.parseFloat(numc.getText().toString());
            } catch (Exception e) {
                num3 = 0;
            }
    

    Instead of this snippet:

    float num1 = Float.parseFloat(numa.getText().toString());
    float num2 = Float.parseFloat(numb.getText().toString());
    float num3 = Float.parseFloat(numc.getText().toString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented activity with edittext and button: After user entered a password and
friends, i have a EditText on simple activity with a button. when every i
I have an activity that contains several user editable items (an EditText field, RatingBar,
I have an Activity in Android, with two elements: EditText ListView When my Activity
I have an activity with two EditTexts. If, in landscape mode, I select the
I have 2 activitys, one is where the user can update or set a
I have one activity with that launches another activity that has a EditText-view. When
I have a EditText box so a user can input names and then click
I have the following class which as you can see contains a EditText, Button
I have a SharedPreferences that saves EditText input from one activity and displays the

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.