OneMoreError
OneMoreError

Reputation: 7728

Eclipse auto complete not working

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

Upvotes: 1

Views: 104

Answers (2)

Akash Thakare
Akash Thakare

Reputation: 22972

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.

Upvotes: 3

Bill
Bill

Reputation: 97

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");

}
}

Upvotes: 2

Related Questions