yousafkh
yousafkh

Reputation: 104

IntelliJ - AutoCompletion not working for new package

I am testing a few Java API, I've created my project called 'MyLearning' where all my src files are located, in src I created another Package callede 'myfiles', now when I import the java.nio.file.Files API, IntelliJ doesn't show me suggestions for this class. But in the main package i.e src folder, the suggestion works totally fine.

Example: enter image description here

The above picture shows my main src folder, where the Files API works totally fine.

enter image description here

But then in the new Package that I've created i.e myfiles, it is showing error on retrieving the methods of Files API. Error is

Cannot resolve symbol 'exists'

Can anyone tell me what could be the poblem here?

Upvotes: 1

Views: 242

Answers (2)

michael-mammut
michael-mammut

Reputation: 2783

You have to call it in a method, not in the class

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {

    public static void main(String[] args) {
        System.out.println("Hello World!");
        Path path = Paths.get("C:\\log.txt");
        System.out.println(Files.exists(path));
    }
}

enter image description here

Upvotes: 1

Jeremy
Jeremy

Reputation: 786

You have to put method calls inside a method.

public void foo()
{
    Files.exists(path);
}

I also noticed that one of the tags you put is intellij-14. The latest version of IntelliJ is 2016.2.

Upvotes: 3

Related Questions