Hello,
i am new to develop the apps.i would like to develop the app which calculate the age between two dates.for this my file MainActivity.java as follows
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import java.util.logging.Handler;
public class MainActivity extends Activity {
private Handler handler;
EditText editText1;
EditText editText2;
EditText editText3;
EditText editText4;
EditText editText5;
EditText editText6;
EditText year_result;
EditText month_result;
EditText days_result;
EditText hour_result;
EditText Minutes_result;
Button btnresult;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1=(EditText)findViewById(R.id.date1);
editText2=(EditText)findViewById(R.id.date2);
editText3=(EditText)findViewById(R.id.month1);
editText4=(EditText)findViewById(R.id.month2);
editText5=(EditText)findViewById(R.id.year1);
editText6=(EditText)findViewById(R.id.year2);
btnresult=(Button)findViewById(R.id.btncal);
year_result=(EditText)findViewById(R.id.year3);
month_result=(EditText)findViewById(R.id.month3);
days_result=(EditText)findViewById(R.id.days3);
hour_result=(EditText)findViewById(R.id.hours3);
Minutes_result=(EditText)findViewById(R.id.minutes3);
btnresult.setOnClickListener(new OnClickListener() {
@override
public void onClick(View view) {
int y3, m3, d3;
int dobyear = Integer.parseInt(editText5.getText().toString());
int presentyear = Integer.parseInt(editText6.getText().toString());
int dobmonth = Integer.parseInt(editText3.getText().toString());
int presentmonth = Integer.parseInt(editText4.getText().toString());
int dobdate = Integer.parseInt(editText1.getText().toString());
int presentdate = Integer.parseInt(editText2.getText().toString());
if (dobmonth > 12 || dobmonth < 1)
return;
while (presentdate < dobdate) {
if (presentmonth == 1) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 2) {
d3 = presentdate + 28;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 3) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 4) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 5) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 6) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 7) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 8) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 9) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 10) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 11) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 12) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else {
d3 = presentdate - dobdate;
days_result.setText(Integer.toString(d3));
}
if(dobmonth>presentmonth)
{
m3=12+presentmonth;
m3=m3-dobmonth;
month_result.setText(Integer.toString(m3));
}
else
{
m3=presentmonth-dobmonth;
month_result.setText(Integer.toString(m3));
}
if (dobmonth>presentmonth)
{
y3=dobyear-presentyear-1;
year_result.setText(Integer.toString(y3));
}
else
{
y3=presentyear-dobyear;
year_result.setText(Integer.toString(y3));
}
}
}
});
}
}
when i run the this app it opens fine but when i press submit button the app is stops working and displays a ANR error.any body facing this issuse please guide me that how to solve this.thanks in advance.
i am new to develop the apps.i would like to develop the app which calculate the age between two dates.for this my file MainActivity.java as follows
import android.app.Activity;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.view.View.OnClickListener;
import java.util.logging.Handler;
public class MainActivity extends Activity {
private Handler handler;
EditText editText1;
EditText editText2;
EditText editText3;
EditText editText4;
EditText editText5;
EditText editText6;
EditText year_result;
EditText month_result;
EditText days_result;
EditText hour_result;
EditText Minutes_result;
Button btnresult;
@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1=(EditText)findViewById(R.id.date1);
editText2=(EditText)findViewById(R.id.date2);
editText3=(EditText)findViewById(R.id.month1);
editText4=(EditText)findViewById(R.id.month2);
editText5=(EditText)findViewById(R.id.year1);
editText6=(EditText)findViewById(R.id.year2);
btnresult=(Button)findViewById(R.id.btncal);
year_result=(EditText)findViewById(R.id.year3);
month_result=(EditText)findViewById(R.id.month3);
days_result=(EditText)findViewById(R.id.days3);
hour_result=(EditText)findViewById(R.id.hours3);
Minutes_result=(EditText)findViewById(R.id.minutes3);
btnresult.setOnClickListener(new OnClickListener() {
@override
public void onClick(View view) {
int y3, m3, d3;
int dobyear = Integer.parseInt(editText5.getText().toString());
int presentyear = Integer.parseInt(editText6.getText().toString());
int dobmonth = Integer.parseInt(editText3.getText().toString());
int presentmonth = Integer.parseInt(editText4.getText().toString());
int dobdate = Integer.parseInt(editText1.getText().toString());
int presentdate = Integer.parseInt(editText2.getText().toString());
if (dobmonth > 12 || dobmonth < 1)
return;
while (presentdate < dobdate) {
if (presentmonth == 1) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 2) {
d3 = presentdate + 28;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 3) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 4) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 5) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 6) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 7) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 8) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 9) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 10) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 11) {
d3 = presentdate + 30;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else if (presentmonth == 12) {
d3 = presentdate + 31;
d3 = d3 - dobdate;
days_result.setText(Integer.toString(d3));
} else {
d3 = presentdate - dobdate;
days_result.setText(Integer.toString(d3));
}
if(dobmonth>presentmonth)
{
m3=12+presentmonth;
m3=m3-dobmonth;
month_result.setText(Integer.toString(m3));
}
else
{
m3=presentmonth-dobmonth;
month_result.setText(Integer.toString(m3));
}
if (dobmonth>presentmonth)
{
y3=dobyear-presentyear-1;
year_result.setText(Integer.toString(y3));
}
else
{
y3=presentyear-dobyear;
year_result.setText(Integer.toString(y3));
}
}
}
});
}
}
when i run the this app it opens fine but when i press submit button the app is stops working and displays a ANR error.any body facing this issuse please guide me that how to solve this.thanks in advance.