Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

Get excited for the Samsung Galaxy S5! Find everything you need and discuss it in our Galaxy S5 Forum!

test: Reply
 
LinkBack Thread Tools
Old April 23rd, 2012, 06:38 PM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Apr 2012
Posts: 1
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default age calculater

hi .
i make this app to calculate the age ..
can any one help me to correct errors

Code:

package com.sa;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.*;
public class XaozActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button n=(Button)findViewById(R.id.sum);
final EditText e=(EditText)findViewById(R.id.editText1);
final EditText e2=(EditText)findViewById(R.id.editText2);
final EditText e3=(EditText)findViewById(R.id.editText3);
final TextView x=(TextView)findViewById(R.id.textView1);
n.setText("push");
n.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
int year=Integer.parseInt(e.getText().toString());
int day=Integer.parseInt(e2.getText().toString());
int month=Integer.parseInt(e3.getText().toString());
Calendar cd = Calendar.getInstance();
if(year > cd.get(Calendar.YEAR)){
x.setText("Invalid ");
System.exit(0);}
if(month < 1 || month > 12){
x.setText("Please enter monthe between 1 to 12 ");}
else{
month--;
if(year == cd.get(Calendar.YEAR)){
if(month > cd.get(Calendar.MONTH)){
x.setText("invalid month ");
System.exit(0);
}
}
}
day = Integer.parseInt(in.readLine());
if(month == 0 || month == 2 || month == 4 || month == 6 || month == 7 || 
month == 9 || month == 11){
if(day > 31 || day < 1){
x.setText("Please enter monthe between 1 to 31 ");
System.exit(0);
}
}
else if(month == 3 || month == 5 || month == 8 || month == 10){
if(day > 30 || day < 1){
x.setText("Please enter monthe between 1 to 30 ");
System.exit(0);
}
}
else{
if(new GregorianCalendar().isLeapYear(year)){
if(day < 1 || day > 29){
x.setText("Please enter monthe between 1 to 29 ");
System.exit(0);
}
}
else if(day < 1 || day > 28){
x.setText("Please enter monthe between 1 to 28 ");
System.exit(0);
}
}
if(year == cd.get(Calendar.YEAR)){
if(month == cd.get(Calendar.MONTH)){
if(day > cd.get(Calendar.DAY_OF_MONTH)){
x.setText("Invalid Date !");
System.exit(0);
}
}
}
}
Calendar bd = new GregorianCalendar(year, month, day);
ageYears = cd.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
if(cd.before(new GregorianCalendar(cd.get(Calendar.YEAR), month, day))){
ageYears--;
ageMonths = (12 - (bd.get(Calendar.MONTH) + 1)) + (bd.get(Calendar.MONTH));
if(day > cd.get(Calendar.DAY_OF_MONTH)){
ageDays = day - cd.get(Calendar.DAY_OF_MONTH);
}
else if(day < cd.get(Calendar.DAY_OF_MONTH)){
ageDays = cd.get(Calendar.DAY_OF_MONTH) - day;
}
else{
ageDays = 0;
}
}
else if(cd.after(new GregorianCalendar(cd.get(Calendar.YEAR), month, day))){
ageMonths = (cd.get(Calendar.MONTH) - (bd.get(Calendar.MONTH)));
if(day > cd.get(Calendar.DAY_OF_MONTH))
ageDays = day - cd.get(Calendar.DAY_OF_MONTH) - day;
else if(day < cd.get(Calendar.DAY_OF_MONTH)){
ageDays = cd.get(Calendar.DAY_OF_MONTH) - day;
}
else
ageDays = 0;
}
else{
ageYears = cd.get(Calendar.YEAR) - bd.get(Calendar.YEAR);
ageMonths = 0;
ageDays = 0;
}
}
}} );
}




itgirl2012 is offline  
Reply With Quote
sponsored links
Old April 23rd, 2012, 07:30 PM   #2 (permalink)
~Play Nice~
 
Unforgiven's Avatar
 
Join Date: Jun 2010
Location: Douglas, MA
Gender: Male
Posts: 21,692
 
Device(s): Note II, S3, Moto X Developer Edition, Nexus 7 (2012 & 2013)
Carrier: Not Provided

Thanks: 13,122
Thanked 14,245 Times in 7,813 Posts
Default

I've move this to the Applications Developers forums so you can get the help you need.
__________________

Join the fun and make some friends, register for free here.
If someone helped, hit Thanks, if you see rude or abusive posts, spam, or threads that need staff attention, hit Report.
Site Rules / Android Forums FAQ
*** Do you want to talk guns? ***

Unforgiven is online now  
Reply With Quote
Old April 23rd, 2012, 10:45 PM   #3 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,936
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 478 Times in 292 Posts
Default

What errors are you receiving? Have you done any debugging yourself yet?
jonbonazza is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:55 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.