1

Basically, I have a situation like this :

enter image description here

I want to know why the auto completion feature does't show the variable lineItems.

I am using Eclipse Kepler on Mac OS and pressing Control + Space.

EDIT :

I have looked at otter similar questions, and I believe I have the preferences set up correctly.

enter image description here

OneMoreError
  • 7,518
  • 20
  • 73
  • 112

2 Answers2

3

Because non-static variables can not be referenced from static context eclipse is much more smarter than we think just add static keyword to your list and it will show the suggestions.

Even if you write full name by your self still no use as it will give you error and from the configuration I think you will get suggestion for other functionalities.

Community
  • 1
  • 1
akash
  • 22,664
  • 11
  • 59
  • 87
2

Make an instance of TreeFormatter, or make the instance variable static.

import java.util.LinkedList;
import java.util.List;


public class TreeFormatter {

List<String> lineItems = new LinkedList<String>();

static List<String> staticlineItems = new LinkedList<String>();

public static void main(String[] args) {

    // make an instance of TreeFormatter
    TreeFormatter tf = new TreeFormatter();
    tf.lineItems.add("foo");

    // or make it static
    staticlineItems.add("bar");

}
}
Bill
  • 97
  • 2
  • 9