Last post I made a number guessing game for Android. It is simple and short, but works well enough. However, my online course teacher pointed out a problem that was in my game.

If the user did not make any guess, but just clicked the guess button, then the app would crash. His challenge to the students was to fix this error, and, praise God, I did. The problem stems from parsing a double that is blank. So, after searching Google, i found some clues, and I edited the code like so:

[CODE]

public void takeGuess(View v)

{

EditText userGuess = (EditText) findViewById(R.id.myGuess);

if (userGuess.getText().toString().equals(“”)) {

Toast toast = Toast.makeText(getApplicationContext(), “Please enter a number!”, Toast.LENGTH_SHORT);

toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER, 0, 0);

toast.show();

} else {

Double uGuess = Double.parseDouble(userGuess.getText().toString());

if (uGuess < hidRandom) {

Toast toast = Toas……

[/CODE]
Now when a user clicks the guess button, the game first checks for a blank field. If the input field is blank, then the game will tell them to enter a number first. If the input has a number, then the game parses the double for the number. Seems to work well enough.
On a side note, this allowed me to make an updated version of an app, so I had to search how to do that. It turned out to be really simple. All that you do is open the build.gradle file and edit these two lines:

 

versionCode 2

versionName "1.1"

 

If you want to play the improved version, you can download it here:

 

https://www.mediafire.com/download/flnbswbblwboo4o
Linux – keep it simple.

Leave a Reply

Your email address will not be published. Required fields are marked *