0

What I want to do is to add Objects from another class(Noten) here and to print them out. I know that this is a common problem but still I can't find a solution.

private ArrayList<Noten> notes123; public void addNotes(Noten newNotes) { if (notes123.size() >= 0) { notes123.add(newNotes); System.out.println(newNotes); } else { System.out.println("No Notes."); } } public void schuelerInfo() { System.out.println("Name: " + name + " Student number: " + nummer); System.out.println("The notes are "); for (Noten note: notes123) { System.out.println(Noten.notenInfo()); } } 
1
  • 4
    Noten.notenInfo() should probably be note.notenInfo() Commented Nov 8, 2014 at 15:53

2 Answers 2

3

Change your for loop from

for (Noten note : notes123){ System.out.println(Noten.notenInfo()); } 

To

for (Noten note : notes123){ note.notenInfo(); } 

As noteInfo method is defined as non static method and you are trying to access it statically using Noten (class). You could only access it on objects which you already have reference stored in arraylist.

Sign up to request clarification or add additional context in comments.

Comments

1

Since notenInfo() is not a static method, it must be called on an instance of a Noten object. For example:

Noten n = new Noten(); n.notenInfo(); 

1 Comment

Noten n = new Noten(); n.notenInfo(); it says 'void' type not allowed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.