###実現したい事
このサイトのサンプルソースを実行したいのですが、実行時に
エラー: メイン・メソッドがクラスtestで見つかりません。次のようにメイン・メソッドを定義してください。 public static void main(String[] args) またはJavaFXアプリケーション・クラスはjavafx.application.Applicationを拡張する必要があります ```とエラーが出てしまいます。ソースにはpublic static void main(String[] args)を記述しているのに何故このエラーが出るのかが分かりません。解決策分かる方回答お願いします。 ###ソース ```Java //test.java import java.io.*; public class test{ public static void main(String[] args) throws IOException { File file = new File("test.txt"); BufferedReader in = new BufferedReader (new InputStreamReader (new ReverseLineInputStream(file))); while(true) { String line = in.readLine(); if (line == null) { break; } System.out.println("X:" + line); } } }
###ソース2
Java
1//ReverseLineInputStream.java 2import java.io.*; 3 4public class ReverseLineInputStream extends InputStream { 5 6 RandomAccessFile in; 7 8 long currentLineStart = -1; 9 long currentLineEnd = -1; 10 long currentPos = -1; 11 long lastPosInFile = -1; 12 13 public ReverseLineInputStream(File file) throws FileNotFoundException { 14 in = new RandomAccessFile(file, "r"); 15 currentLineStart = file.length(); 16 currentLineEnd = file.length(); 17 lastPosInFile = file.length() -1; 18 currentPos = currentLineEnd; 19 } 20 21 public void findPrevLine() throws IOException { 22 23 currentLineEnd = currentLineStart; 24 25 // There are no more lines, since we are at the beginning of the file and no lines. 26 if (currentLineEnd == 0) { 27 currentLineEnd = -1; 28 currentLineStart = -1; 29 currentPos = -1; 30 return; 31 } 32 33 long filePointer = currentLineStart -1; 34 35 while ( true) { 36 filePointer--; 37 38 // we are at start of file so this is the first line in the file. 39 if (filePointer < 0) { 40 break; 41 } 42 43 in.seek(filePointer); 44 int readByte = in.readByte(); 45 46 // We ignore last LF in file. search back to find the previous LF. 47 if (readByte == 0xA && filePointer != lastPosInFile ) { 48 break; 49 } 50 } 51 // we want to start at pointer +1 so we are after the LF we found or at 0 the start of the file. 52 currentLineStart = filePointer + 1; 53 currentPos = currentLineStart; 54 } 55 56 public int read() throws IOException { 57 58 if (currentPos < currentLineEnd ) { 59 in.seek(currentPos++); 60 int readByte = in.readByte(); 61 return readByte; 62 63 } 64 else if (currentPos < 0) { 65 return -1; 66 } 67 else { 68 findPrevLine(); 69 return read(); 70 } 71 } 72}
###コンパイルと実行
javac test.java ReverseLineInputStream.java (コンパイル)
java test ReverseLineInputStream (実行)
###testクラスのみコンパイル実行
reverse>dir 2018/09/10 21:12 <DIR> . 2018/09/10 21:12 <DIR> .. 2018/08/30 21:16 1,306 test.txt 2018/09/09 17:05 1,275 ReverseLineInputStream.class 2018/09/09 17:02 2,030 ReverseLineInputStream.java 2018/09/09 18:49 1,011 test.class 2018/09/09 17:05 404 test.java 6 個のファイル 7,905 バイト 2 個のディレクトリ 693,164,072,960 バイトの空き領域 reverse>java test エラー: メイン・メソッドがクラスtestで見つかりません。次のようにメイン・メソッドを定義してください。 public static void main(String[] args) またはJavaFXアプリケーション・クラスはjavafx.application.Applicationを拡張する必要があります reverse>javac *.java reverse>java test エラー: メイン・メソッドがクラスtestで見つかりません。次のようにメイン・メソッドを定義してください。 public static void main(String[] args) またはJavaFXアプリケーション・クラスはjavafx.application.Applicationを拡張する必要があります
###実行環境
reverse>ver
Microsoft Windows [Version 10.0.17134.228]
reverse>java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
reverse>javac -version
javac 1.8.0_171
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/10 12:24
2018/09/10 12:34
2018/09/10 13:31
2018/09/10 22:22
退会済みユーザー
2018/09/10 22:33
2018/09/11 07:09
2018/09/11 07:16