Question: The CASE 2 part of TEST.JAVA is not working with an error. What should I do? TEST.JAVA /* * Click nbfs:/bhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license

The CASE 2 part of TEST.JAVA is not working with an error. What should I do?



TEST.JAVA

/* * Click nbfs:/bhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs:/bhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */package MyApp;import MyLibs.Member;import MyLibs.Team;import java.util.Scanner;/** * * @author apple */public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Team basketBall; basketBall = new Team("BasketBall", 5, 18, 21); Member[] m = new Member[basketBall.getMaxMember()]; int count = 0; int choice = 0; while(choice != 3) { System.out.println("BasketBall Team Application"); System.out.println("---------------------------"); System.out.println("[1] Apply in the team"); System.out.println("[2] Show Applicants"); System.out.println("[3] Exit"); System.out.println("---------------------------"); System.out.print("Choice: "); choice = sc.nextInt(); switch (choice) { case 1 -> { if(basketBall.getMemberCnt() == 5) { System.out.println("Basketball team is no longer accepting applicants"); continue; } System.out.print("Enter name:"); String name = sc.next(); System.out.println("Enter age:"); int age = sc.nextInt(); if(age  basketBall.getMaxAge()) { System.out.println("Sorry you are not qualified!"); }else { System.out.println("Welcome to the basketball team!"); Member member = new Member(name, age); m[count++] = member; basketBall.addMember(member); } } case 2 -> { for (Member member : m) { System.out.println(member.getName()+" , "+ member.getAge()); } } case 3 -> System.out.println("Thank You!"); default -> { } } } } private static void getName() { throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs:/bhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody }}


MEMBER.JAVA

/* * Click nbfs:/bhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs:/bhost/SystemFileSystem/Templates/Other/File.java to edit this template */package MyLibs;/** * * @author apple */public class Member { public String name; public int age; public Member(String name, int age){ this.name = name; this.age = age; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public int getAge() { return this.age; } public void setAge(int age) { this.age = age; }}


TEAM.JAVA

/* * Click nbfs:/bhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs:/bhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */package MyLibs;/** * * @author apple */public class Team { public String name; public Member [] members; public int memberCnt; public int maxMember; public int minAge; public int maxAge; public Team(String name, int maxMember, int minAge, int maxAge) { this.name = name; this.maxMember = maxMember; this.minAge = minAge; this.maxAge = maxAge; members = new Member[this.maxMember]; this.memberCnt = 0; } public void addMember(Member m) { members[this.memberCnt] = m; this.memberCnt++; } public boolean checkQualification(Member m) { return !(m.getAge() this.maxAge); } public int getMaxMember() { return maxMember; } public void setMaxMember(int maxMember) { this.maxMember = maxMember; } public int getMinAge() { return minAge; } public void setMinAge(int minAge) { this.minAge = minAge; } public int getMaxAge() { return maxAge; } public void setMaxAge(int maxAge) { this.maxAge = maxAge; } public int getMemberCnt() { return memberCnt; } public void setMemberCnt(int memberCnt) { this.memberCnt = memberCnt; }}


[1] Apply in the team [2] Show Applicants [3] Exit Choice: 2

[1] Apply in the team [2] Show Applicants [3] Exit Choice: 2 joji, 19 alex, 20 Exception in thread "main" java.lang.NullPointerException: Cannot invoke "MyLibs.Member.getName()" because "member" is null at MyApp. Test.main(Test.java:59) /Users/apple/Library/Caches/NetBeans/13/executor-snippets/run.xml:111: /Users/apple/Library/Caches/NetBeans/13/executor-snippets/run.xml:68: BUILD FAILED (total time: 16 seconds) The following error occurred while executing this line: Java returned: 1

Step by Step Solution

3.38 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The error youre encountering is a NullPointerException in the Testjava file on lin... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!