2015-11-04 74 views
1

***我有錯誤,指出:我想讀一個CSV文件,並在Excel中顯示爲csv文件

Error: Main method not found in class Main, please define the main method as:
public static void main(String[] args) I solved the previous issue but I'm now getting this error: C:\Program Files\Java\jre1.8.0_60\bin\javaw.exe (Nov 8, 2015, 7:41:12 PM)
When attempting to run this code:*** package filtermovingaverage;

import java.io.BufferedReader; 
import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileReader; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.util.ArrayList; 

public class Main { 
    //public static void main(String[] args){ 


    private static double freqS = 100; 
    static ArrayList<Double> sec = null; 
    private static double[] pressure = new double[20481]; 

    void func() throws IOException 
    { 
     BufferedReader read = new BufferedReader(new FileReader(new File("C:\\Users\\KwakuK\\Downloads\\smith2.csv")));   
     String currentLine = new String(); 
     currentLine = read.readLine(); 
     int i = 0; 
     //make some computation 
     while((currentLine = read.readLine()) != null) 
     { 
      String[] numbers = currentLine.split(","); // split the string into sub strings 
      if(numbers.length >= 3) 
      { 
        System.out.println("currentLine: " + " " + currentLine); 

       pressure[i++] = Double.parseDouble(numbers[2]); // when you do the 2, it's the third column which is the pressure 
      } 
     } 
    } 

    public static void setupFirstPlot() throws FileNotFoundException{ 
     sec = new ArrayList<Double>(); 
     double ws = 1/freqS; 
     double n = (pressure.length)*ws; 

     for(double i = 0; i < n; i = i + ws){ 
      sec.add(i); 
     } 
     PrintWriter pw = new PrintWriter(new File("plot13.csv")); 
     for(int i = 0; i < pressure.length; i++){ 
      pw.write(sec.get(i)+","+pressure[i]+"\n"); 
     } 
     pw.close(); 
    } 

    public static void main(String[] args) throws FileNotFoundException{ 
     setupFirstPlot(); 
     System.out.println(); 
    } 
} 
+0

另外,您可能想查看Apache POI;它是一個幫助您創建Excel電子表格的庫(等等)。 –

+0

如上所述[Apache POI](https://poi.apache.org/spreadsheet/examples.html)是一個偉大的庫。但是,您的代碼似乎沒有任何問題。它顯然有一個主要方法。你在用什麼IDE? –

+0

我正在使用JavaSE-1.7 –

回答

0

嘗試增加package filtermovingaverage;來此之上java文件。