Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get the error "File cannot be resolved to a type"?

Tags:

java

Here's part of my code

try{

    BufferedReader in= new BufferedReader(new InputStreamReader(System.in));

    while ((line= in.readLine())!="exit"){

    System.out.println("Enter command");
    line=in.readLine();
    Command currentCommand=new Command(line);



    File currentFile= new File(currentCommand.getLsPath());

The method currentCommand.getLsPath() returns a string, which is mendatory for the File Constracture, and still I get this error: File cannot be resolved to a type

What is the problem?

like image 655
Unknown user Avatar asked May 13 '11 19:05

Unknown user


2 Answers

Chances are you've just missed:

import java.io.File;

from the top of your source file.

You could use

 import java.io.*; 

I typically use single-type imports.

like image 51
Jon Skeet Avatar answered Oct 18 '22 21:10

Jon Skeet


You need to include either

import java.io.File;

or

import java.io.*;

at the top of your source file.

like image 45
Ernest Friedman-Hill Avatar answered Oct 18 '22 19:10

Ernest Friedman-Hill