I have a array list and it needs to return allteams object at the end but i'm unable to do that and when passing null it gives in an null pointer exception please help me solve this issue. Here is the code sample:
private ArrayList<Team> getData() {
Intent localIntent = getIntent();
localIntent.getIntExtra("det", 0);
if (localIntent.hasExtra("beg")) {
Team t1 = new Team("Day 1: Chest, Back, Shoulders, Legs, Biceps, Triceps");
t1.players.add("Chest – Barbell Bench Press – 4 sets of 8 reps");
t1.players.add("Back – Lat-pulldowns – 4 sets of 10 reps");
t1.players.add("Shoulders – Seated Dumbbell Press – 4 sets of 10 reps");
t1.players.add("Legs – Leg Extensions – 4 sets of 10 reps");
t1.players.add("Biceps – Barbell Bbicep Curls – 3 sets of 10 reps");
t1.players.add("Triceps – Triceps Rope Pushdowns – 3 sets of 15 reps");
Team t2 = new Team("Day 2: Legs, Triceps, Biceps, Chest, Back, Shoulder");
t2.players.add("Legs – Leg Press Machine – 4 sets of 8 reps");
t2.players.add("Triceps – Overhead Bar Extensions – 3 sets of 20 reps");
t2.players.add("Biceps – EZ Bar Curls – 4 sets of 10 reps");
t2.players.add("Chest – Machine Chest Press – 4 sets of 10 reps");
t2.players.add("Back – T-Bar Row – 4 sets of 10 reps");
t2.players.add("Shoulders – Lateral Raises – 3 sets of 20 reps");
Team t3 = new Team("Day 3: Shoulders, Back, Chest, Legs, Triceps, Biceps");
t3.players.add("Shoulders – Upright Rows – 3 sets of 15 reps");
t3.players.add("Back – Close-Grip Pulldowns – 4 sets of 12 reps");
t3.players.add("Chest – Fly – 4 sets of 10 reps");
t3.players.add("Legs – Lunges – 3 sets of 10 reps per leg");
t3.players.add("Triceps – Skullcrushers – 3 sets of 15 reps");
t3.players.add("Biceps – Hammer Curls – 3 sets of 12 reps");
ArrayList<Team> allTeams = new ArrayList<Team>();
allTeams.add(t1);
allTeams.add(t2);
allTeams.add(t3);
return allTeams;
} else if (localIntent.hasExtra("inter")) {
Team t1 = new Team("Day 1: Chest, Shoulders and Triceps");
t1.players.add("Bench Press – 3 sets of 10, 10, 8 (adding weight) reps");
t1.players.add("Incline Dumbbell Bench Press – 3 sets of 10 reps");
t1.players.add("Chest Dip – 3 sets of MAX reps");
t1.players.add("Skullcrushers – 3 sets of 8-10 Reps");
t1.players.add("One Arm Dumbbell Extension – 3 sets of 10 reps");
t1.players.add("Tricep Extension – 3 sets of 10 reps");
t1.players.add("Barbell Front Raise – 4 sets of 12 reps");
t1.players.add("Dumbbell Lateral Raise – 4 sets of 15, 12, 8, 8 (adding weight) reps");
Team t2 = new Team("Day 2: Back and Biceps");
t2.players.add("Wide Grip Pull Up 3 sets of MAX reps");
t2.players.add("Lat Pull Down – 3 sets of 10 reps");
t2.players.add("Straight Arm Lat Pull Down – 3 sets of 10 reps");
t2.players.add("Standing Barbell Curl – 3 sets of 8-10 reps");
t2.players.add("Preacher Curl – 3 sets of 10 reps");
t2.players.add("Incline Dumbbell Curl – 3 sets of 10 reps");
Team t3 = new Team("Day 3: Legs");
t3.players.add("Squat – 4 sets of 10,10,8,8 reps");
t3.players.add("Dumbbell Lunge – 3 sets of 8 on each leg");
t3.players.add("Leg Press – 3 sets of 12 reps");
t3.players.add("Leg Curl – 3 sets of 15 reps");
t3.players.add("Leg Extension – 3 sets of 15 reps");
t3.players.add("Standing Calf Raise – 5 sets of 10,8,8,8,6 (heavy)reps");
t3.players.add("Seated Calf Raise – 5 sets of 15 (light) reps");
Team t4 = new Team("Day 4: Shoulders, chest, and Triceps");
t4.players.add("Barbell Bench Press – 3 sets of 10, 10, 8 reps");
t4.players.add("Dumbbell Flys – 3 sets of 10 reps");
t4.players.add("Cable Crossovers – 3 sets of 10 reps");
t4.players.add("Close Grip Bench Press – 4 sets of 10, 10, 8, 6 reps");
t4.players.add("Lying Dumbbell Extension – 3 sets of 10 reps");
t4.players.add("Tricep Kickback – 3 sets of 10 reps");
t4.players.add("Seated Dumbbell Press – 4 sets of 10, 10, 8, 8 reps");
t4.players.add("One Arm Cable Lateral Raise – 3 sets of 12 reps");
Team t5 = new Team("Day 5: Back and Biceps");
t5.players.add("Seated Row – 4 sets of 10 reps");
t5.players.add("Bent Over Barbell Row – 3 sets of 10 reps");
t5.players.add("Bent Over Row – 3 sets of 12 reps");
t5.players.add("Smith Machine Upright Row – 3 sets of 8-10 reps");
t5.players.add("Cable Curl – 4 sets of 8-10 reps");
t5.players.add("Concentration Curl – 3 sets of 10 reps");
t5.players.add("Reverse Barbell Curl – 3 sets of 10 reps");
ArrayList<Team> allTeams = new ArrayList<Team>();
allTeams.add(t1);
allTeams.add(t2);
allTeams.add(t3);
allTeams.add(t4);
allTeams.add(t5);
return allTeams;
}
return null;
}
Please help me solve this issue what can i do to get rid of this problem at the end instead of null it should be returning allteams.
By these code if not matched any thing its return null for these case Add last else and set it default values .whether its null or not matched it excute else statement.
if()
{
}
else if()
{
}
else {
Team t1 = new Team("Day 1: Chest, Shoulders and Triceps");
t1.players.add("Bench Press – 3 sets of 10, 10, 8 (adding weight) reps");
t1.players.add("Incline Dumbbell Bench Press – 3 sets of 10 reps");
t1.players.add("Chest Dip – 3 sets of MAX reps");
t1.players.add("Skullcrushers – 3 sets of 8-10 Reps");
t1.players.add("One Arm Dumbbell Extension – 3 sets of 10 reps");
t1.players.add("Tricep Extension – 3 sets of 10 reps");
t1.players.add("Barbell Front Raise – 4 sets of 12 reps");
t1.players.add("Dumbbell Lateral Raise – 4 sets of 15, 12, 8, 8 (adding weight) reps");
ArrayList<Team> allTeams = new ArrayList<Team>();
allTeams.add(t1);
return allTeams;
}