2015-09-06 113 views
0
package IO; 
import java.io.*; 
import java.util.ArrayList; 

public class driver { 

    public static void main(String args[]) { 

     int s; 

     try { 

      //Scanner in = new Scanner(System.in); 
      //System.out.println("Enter The number of files you want to create"); 
      //s = in.nextLine(); 
      //takes the number of files 

      ArrayList<String> obj = new ArrayList<String>(); 
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 
      System.out.println("Enter the number of files you want to create"); 
      String num = br.readLine(); 
      int x = Integer.parseInt(num); 

      // takes the names of file 
      for (int i = 0; i < x; i++) { 
       System.out.println("Enter the name for file:"); 
       String name = br.readLine(); 
       Integer.parseInt(name); 
       obj.add(name); 
      } 

     } catch (IOException o) { 
      System.out.println("Exception^^^^^^^^^^^^^"); 

     } 
    } 
} 

這上面是我的代碼,但是當我編譯它像javac的driver.java然後Java驅動程序的命令行它給了我錯誤無法加載主類主...請幫我排序這個錯誤..這個代碼btw包含文件處理,這將在稍後實施!編譯錯誤 - 無法找到或Java錯誤負載類

+2

[可能的複製(http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – Deftwun

+0

什麼?請幫助我成功編譯此代碼。 –

+1

你應該確實修復你的縮進。 – Zarwan

回答

1

我修改您的代碼檢查下面的代碼工作對我來說..

import java.io.*; 
import java.util.ArrayList; 

public class Driver{ 

    public static void main(String args[]){ 

    int s; 

    try{ 
     ArrayList<String> obj = new ArrayList<String>(); 
     BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); 
     System.out.println("Enter the number of files you want to create");  
     String num = br.readLine(); 
     int x=Integer.parseInt(num); 

     // takes the names of file 

     for(int i=0;i<x;i++){ 
     System.out.println("Enter the name for file:"); 
     String name = br.readLine(); 
     Integer.parseInt(name); 
     obj.add(name); 
     } 
    }catch(Exception e){ 

    } 
    } 
} 
+0

它仍然給不能加載文件演示錯誤:/ –

+0

哦THANKYOU它的工作,但不知道它是什麼問題:/ –

+0

你有包IO;聲明,聲明的包「IO」與例外包不匹配。如果您想了解軟件包,請參閱本教程 - https://docs.oracle.com/javase/tutorial/java/package/。接下來的事情是使用小寫字母表示軟件包名稱的最佳做法。 –

0
  1. 您是否正確定位文件?
  2. 刪除package IO;然後編譯它。 它編譯成功。 enter image description here
相關問題