まず第一に、 私はここで見つけたすべてのスレッドを読みました。それらのどれも私が直面している問題を解決しませんでした。私はプロのJava開発者ではなく、このクラスで同僚を支援しているだけなので、気楽にやってください。cannot find symbol
最初に基本的な状況を説明しましょう。
src/pdfDownloadpdfDownload
にというパッケージがあります。このディレクトリには2つのファイルがあります:と。PDFItem.java
PDFItemParser.java
どちらもパブリッククラスです。以下に添付されているクラスのコードを見つけることができます。私が使用してEclipse IDE
いるのは、警告もエラーも表示されません**。
それらをコンパイルすると、次のエラーメッセージが表示されます。
PDFItemParser.java:19: cannot find symbol symbol : class PDFItem
location: class pdfDownload.PDFItemParser public static
ArrayList<PDFItem> parseFile(String filePath){
^ PDFItemParser.java:11: cannot find symbol symbol : class PDFItem location: class pdfDownload.PDFItemParser
ArrayList<PDFItem> items = parseFile("data.csv");
^ PDFItemParser.java:20: cannot find symbol symbol : class PDFItem location: class pdfDownload.PDFItemParser ArrayList<PDFItem>
items = new ArrayList<PDFItem>(); /* Creates an ArrayList from type
PDFItem which will contain all parsed ItemObjects */
^ PDFItemParser.java:20: cannot find symbol symbol : class PDFItem location: class pdfDownload.PDFItemParser
ArrayList<PDFItem> items = new ArrayList<PDFItem>(); /* Creates an
ArrayList from type PDFItem which will contain all parsed ItemObjects
*/
^ PDFItemParser.java:21: cannot find symbol symbol : class PDFItem location: class
pdfDownload.PDFItemParser items.add(new PDFItem());
^ 5 errors
クラスは両方ともパブリックであり、正しいディレクトリとパッケージにあります。また、クラス内のEclipseでオートコンプリートを取得します。私と私の同僚は、これを2時間解決するのに苦労しています。本当に簡単なことで申し訳ありませんが、このエラーの通常のケースが当てはまらなかったため、解決できませんでした。前もって感謝します!PDFItem
PDFItemParser
編集:私はそれらを(Mac)ターミナルでコンパイルします。ターミナルでパスを開き、次のように入力します。
javac PDFItem.java
その後
javac PDFItemParser.java
PDFItem-クラスコード:
package pdfDownload;
public class PDFItem {
String imageURL;
String pdfURL;
boolean imageLoaded;
boolean pdfLoaded;
String name;
public PDFItem() {
}
public PDFItem(String name) {
this.name = name;
}
}
PDFItemParser - Class Code:
---------------------------
package pdfDownload;
import java.util.ArrayList;
import java.io.*;
public class PDFItemParser {
public static void main(){
ArrayList<PDFItem> items = parseFile("data.csv");
if(items != null){
System.out.println(items.get(0).name);
}
}
public static ArrayList<PDFItem> parseFile(String filePath){
ArrayList<PDFItem> items = new ArrayList<PDFItem>(); /* Creates an ArrayList from type PDFItem which will contain all parsed ItemObjects */
items.add(new PDFItem());
try{
FileInputStream fstream = new FileInputStream(filePath);
DataInputStream in = new DataInputStream(fstream); /* Get the object of DataInputStream */
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) { /* Read File Line By Line */
System.out.println (strLine); /* Print the content on the console */
}
in.close(); /* Close the input stream */
}
catch (Exception e){ /* Catch exception if any */
System.err.println("Error: " + e.getMessage());
}
return items; /* Returns ArrayList */
}
}