0

have this class

 public class Taxonomia {

    private static ArrayList<String> hijas;
    private static String padre;

    public Taxonomia (String p, ArrayList<String> h){
        hijas = h;
        padre = p;
        }

}

used in another class like this:

public class TablaSimbolica {

private static ArrayList<Taxonomia> taxonomias = new ArrayList<Taxonomia>();

public static void addTaxonomica(){

    System.out.println("enter value: ");
    String padre = Entrada.read(); //reads input and returns String
    System.out.println("entre value comma separated: ");
    String reemplazado = Entrada.read();
    ArrayList<String> items = new ArrayList<String>(Arrays.asList(reemplazado.split("\\s*,\\s*")));
    Taxonomia t = new Taxonomia (padre, items);
    taxonomias.add(t);  

}

when called from the main simple as this (print its just a for...)

TablaSimbolica.addTaxonomica();
TablaSimbolica.addTaxonomica();
TablaSimbolica.printTax();

all the objects are the same, and i cant figure out where it is im missing the creation of a new object or something like that. thanks in advance!

1
  • only one value of static variable can exists at a time. leave the unnecessary static out and you are good to go. Commented Apr 29, 2014 at 23:29

1 Answer 1

1

Your class variables in the Taxonomia class are static, meaning only one of each for the entire class, no matter how many instances.

Make it one per instance by removing static. Change

private static ArrayList<String> hijas;
private static String padre;

to

private ArrayList<String> hijas;
private String padre;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.