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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:07:48+00:00 2026-05-25T11:07:48+00:00

respected all; I am new to programming and find a barrier i.e on clicking

  • 0

respected all;

I am new to programming and find a barrier i.e on clicking the button without any thing being inputted in the Edittext box converts mine activity to crash.

So after research i got Try and catch methods and it works good .

     public void clickDiv(View button){
     try{
         EditText Input = (EditText) findViewById(R.id.editext);

        String input = Input.getText().toString();

         String empty = "";

         Float floatInput = new Float (input);

         TextView TextShow = (TextView) findViewById(R.id.textView1);

         String Newinput = floatInput.toString();

         TextShow.setText(Newinput);

         if (answer == 0){

             answer =  (answer+1) / floatInput  ;
         }else{
             answer =  (answer) / floatInput  ;
         }
         String answerString = answer.toString();

         TextShow.setText(answerString);

         Input.setText(empty); }
         catch (Exception e) {
         AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(this).create();
          alertDialog.setMessage("Could not find the operand");
         alertDialog.show();
      }}

But the main problem is that i have to use it in all the button methods.
is there any other way other to avoid this repetition in code.

Please help..

  • 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-25T11:07:48+00:00Added an answer on May 25, 2026 at 11:07 am

    modify the code like this. Hope it helps you.

    public void clickDiv(View button){
     try{
         EditText Input = (EditText) findViewById(R.id.editext);
    
        String input = Input.getText().toString();
    
         //if no input, set the error to the edittext and return
         if(input.trim().length()==0){
            Input.setError("An input is required");
            return;
         }
         String empty = "";
    
         Float floatInput = new Float (input);
    
         TextView TextShow = (TextView) findViewById(R.id.textView1);
    
         String Newinput = floatInput.toString();
    
         TextShow.setText(Newinput);
    
         if (answer == 0){
    
             answer =  (answer+1) / floatInput  ;
         }else{
             answer =  (answer) / floatInput  ;
         }
         String answerString = answer.toString();
    
         TextShow.setText(answerString);
    
         Input.setText(empty); }
         catch (Exception e) {
         AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(this).create();
          alertDialog.setMessage("Could not find the operand");
         alertDialog.show();
      }}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

GCC is a very well respected multi-language compiler (from what I've gathered). One thing
I'm quite new to iphone programming and I want to do the following stuff:
Respected All, I am newly working on android technology. I have use map view
First of all, please excuse me as I am a bit new to this
This seemed to me like the easiest thing to find, a simple way to
I am fairly new to iPhone/ObjC programming, though I have several years of experience
The respected open source .NET wrapper implementation ( SharpBITS ) of Windows BITS services
Maybe is a often repeated question here, but i can't find anything similar with
As a new entry to the software development industry I tried to develop my
I am new to iphone development.. am creating one small application where two viewcontrollers

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.