簡體   English   中英

為什么我會收到錯誤“文件無法解析為某種類型”?

[英]Why do I get the error “File cannot be resolved to a type”?

這是我的代碼的一部分

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

方法currentCommand.getLsPath()返回一個字符串,這對於File Constracture是可以修改的,但我仍然收到此錯誤: File cannot be resolved to a type

問題是什么?

你錯過了很多機會:

import java.io.File;

從源文件的頂部。

可以

 import java.io.*; 

我通常使用單一類型的導入。

你需要包括

import java.io.File;

要么

import java.io.*;

在源文件的頂部。

我曾經收到過這個錯誤,即使我已經導入了java.io.File。 我認為這是一些奇怪的,臨時的Eclsipse故障。 當我對代碼進行其他更改,然后再次保存時,錯誤自行解決。

你很可能忘記導入java.io.File但基本上編譯器告訴你它找不到“文件”類。

有關詳細信息,請參閱特定於“ 文件無法恢復為某種類型 ”的此Java錯誤頁面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM