0

I am new to ArrayList and trying to create an object with a object inside but with format of array, someone can help me please.

Here is the code if you can help me, thank you in advance.

The case 1 is for receiving the values by keyboard.

case 1:                  
  System.out.print("Ingrese el nombre del jugador: ");              
  objPartido.getObjTeam1().getObjPlayer().setNombre(sc.nextLine());          
  jugadorBaby.add(objPartido.getObjTeam1().getArrPlayer()[1]);           
  sc.nextLine();
  partidoBaby.add(objPartido);
  break;    

In the case 2 i need to show the variable Nombre of the object player that i enter by keyboard in case 1

case 2:
  for(int i=0;i<partidoBaby.size();i++){
    muestraPartido(objPartido);                   
  }     break;     

I wanna know how to do "muestraPartido" show me the case 1 values.

muestraPartido(Partido objPartido):

public static void muestraPartido(Partido objPartido){
  for(int i=0;i<jugadorBaby.size();i++){       
    String n= jugadorBaby.get(i).getNombre();
    System.out.println(n); }

t.Partido

private Team objTeam1;
private Team objTeam2;

public Partido() {
    objTeam1 = new Team();
    objTeam2 = new Team();}

t.Team

 private Player[] arrPlayer;
 private Player objPlayer;

 public Team() {
    arrPlayer = new Player[6];
    objPlayer= new Player(); }

 public Team(Player[] arrPlayer) {
    this.arrPlayer = arrPlayer; }
Andres
  • 1
  • 1
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Karol Dowbecki Nov 18 '18 at 20:07
  • Hi @Andres. I have reformatted your question and code in order to make it more readable. Unfortunately a lot of the code posted adds no value. There are more important code fragments you´re not sharing. Regarding your question: The method muestraPartido is iterating over elements in jugadorBaby. Let´s assume this is a List. In each iteration the code is trying to get the element at position i and invoke getNombre() on it. Probably there is no element in the list at a particular position. Just try to debug this line and have a look on the list´s items. – ibexit Nov 18 '18 at 20:29
  • can i send you the full code?, if u dont bother helping me? – Andres Nov 18 '18 at 20:33

0 Answers0