[Java for Android App Development] frenzyboi:
You're targetting min sdk of 8, which doesn't allow checking if string ".isEmpty()", which

IF I'M NOT WRONG

, is not included in older version of Android due to different version of Java. So I've changed it to check if the length is less than 0 before calculating.

.length() < 1

Secondly, you're converting the values of the Textbox

BEFORE

you check if the input is empty or not. Check before converting. Because if your input is empty, it is unable to convert a NULL into a double.

Lastly, one small error. Your DIVIDE is still PLUS. I've corrected it for you.

Sorry for the late reply! Hope there ain't any error.

Oh, one small tip. Try reading up "Try and Catch" for Android. Good for preventing force closing of apps.

package com.example.caltest;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
private EditText txtN1;
private EditText txtN2;
private EditText txtAn;
private Button Add, Sub, Div, Mul, Clr, Ext;
private AlertDialog.Builder dlgAlert;
double a = 0, b = 0, c = 0;

[MENTION=439709]override[/MENTION]
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
dlgAlert = new AlertDialog.Builder(MainActivity.this);
Add = (Button) findViewById(R.id.btnAdd);
Sub = (Button) findViewById(R.id.btnSub);
Div = (Button) findViewById(R.id.btnDiv);
Mul = (Button) findViewById(R.id.btnMul);
Clr = (Button) findViewById(R.id.btnClr);
Ext = (Button) findViewById(R.id.btnExt);
txtN1 = (EditText) findViewById(R.id.txtNum1);
txtN2 = (EditText) findViewById(R.id.txtNum2);
txtAn = (EditText) findViewById(R.id.txtAns);
Add.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {

if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a + b;
txtAn.setText("" + c);
}
}
});
Sub.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {

if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a - b;
txtAn.setText("" + c);
}
}
});
Mul.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {

if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a * b;
txtAn.setText("" + c);
}
}
});
Div.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {

if (txtN1.getText().toString().length() < 1
|| txtN2.getText().toString().length() < 1) {
dlgAlert.setMessage("Please enter number in text box!");
dlgAlert.setTitle("Enter Number");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else if (b == 0) {
dlgAlert.setMessage("Number can not be zero");
dlgAlert.setTitle("Divider Zero!");
dlgAlert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
dlgAlert.setCancelable(true);
dlgAlert.create().show();
} else {
a = Double.parseDouble(txtN1.getText().toString());
b = Double.parseDouble(txtN2.getText().toString());
c = a/b;
txtAn.setText("" + c);
}
}
});
Clr.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {
txtN1.setText("");
txtN2.setText("");
txtAn.setText("");
}
});
Ext.setOnClickListener(new View.OnClickListener() {

[MENTION=439709]override[/MENTION]
public void onClick(View arg0) {
finish();
}
});
}

[MENTION=439709]override[/MENTION]
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}