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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:49:58+00:00 2026-06-04T18:49:58+00:00

Anybody knows how to prevent an Android application crashing when ab EditText has no

  • 0

Anybody knows how to prevent an Android application crashing when ab EditText has no value in it?

EDIT: Sorry, I posted this with my phone. Here you go:

import java.util.Random;

import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;

public class RandomButtonActivity extends Activity implements SensorEventListener
{
    public float x = 0, y = 0, z = 0;           
    public float a = 10, b = 10, c = 10;
    public float k = 4;
    public int j = 0, i = 0;
    public int rand = 0;
    public String j1;
    public String i1;


    TextView testo;
    TextView ultimo;

    EditText limiteMin;
    EditText limiteMax;

    Random generator = new Random();

    SensorManager sm;

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

        testo = (TextView) findViewById(R.id.textView1);
        ultimo = (TextView) findViewById(R.id.textView4);

        limiteMin = (EditText) findViewById(R.id.editText2);
        limiteMax = (EditText) findViewById(R.id.EditText01);

        sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        sm.registerListener(this, sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);

        random();
    }

    public void onSensorChanged(SensorEvent event)
    {
        x = event.values[0];
        y = event.values[1];
        z = event.values[2];        

        if(x>a+k || x<a-k || y>b+k || y<b-k || z>c+k || z<c-k)
        {
            rand = random();
        }
        a = x;
        b = y;
        c = z;
    }

    public int random() 
    {
        j = Integer.parseInt(limiteMin.getText().toString());
        i = Integer.parseInt(limiteMax.getText().toString());
        int v = 0;

            if(i==0 && j==0)
            {
                v = generator.nextInt();                       
            }
            else if(j>=i && j!=0)
            {               
                v = 0;
            }           
            else
            {
                i = i+1;
                do
                {
                v = generator.nextInt(i);
                testo.setText("Random: "+v);
                }
                while(v<j);
            }
            testo.setText("Random: "+v);   
            ultimo.setText("Random precedente: "+rand);

        return v;
    }

    public void onAccuracyChanged(Sensor sensor, int accuracy) 
    {
    }
}

The program crashes only when 1 of 2 EditTexts is empty and the method random() is called.

  • 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-04T18:49:59+00:00Added an answer on June 4, 2026 at 6:49 pm

    Apply following code,

      EditText et= (EditText)findViewById(R.id.editText);
      if(et.getText.toString.equals(null) || et.getText.toString.equals(""))
       {
           Toast.makeText(this,"please enter something in text box",Toast.LENGTH_LONG).show(); 
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

anybody knows if it is possible to do calls from flash to asp.net mvc
Anybody knows where to copy the AjaxControlToolkit.DLL so that it appears in the Toolbox
Anybody knows where the :// or the // comes from in most URIs syntaxes?
anybody knows what can be the reason for when i start a service from
Anybody knows a good book or two (or resources) for JVM Tuning? I am
Anybody knows proper python implementation of TEA (Tiny Encryption Algorithm)? I tried the one
Anybody knows how to print single-linked list in reverse order (one pass and a
Anybody knows how MySql allocates memory for text and blob in case i'm inserting
Does anybody knows what that error is pointing? ORA-06550: line 1, column 129: PLS-00103:
Does anybody knows how to implement expand/collapse only on icon click in collapsibe div?

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.