Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

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
Sponsors
Old April 23rd, 2012, 07:30 PM   #2 (permalink)
eschew obfuscation
 
Unforgiven's Avatar
 
Join Date: Jun 2010
Location: Douglas, MA
Gender: Male
Posts: 14,509
 
Device(s): OG Droid, DroidX2, HTC Rhyme, Kindle Fire, Galaxy Nexus, Nexus 7 (8GB & 16GB)
Carrier: VZW

Thanks: 7,147
Thanked 8,094 Times in 4,619 Posts
Default

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

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
*** Check out the new AF forum app!!! ***

I'm supporting BabyBlues with this. Please consider this worthy cause. Details

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,925
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 462 Times in 285 Posts
Default

What errors are you receiving? Have you done any debugging yourself yet?
jonbonazza is online now  
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 09:10 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.