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^^^^^^^^^^^^^");

        }
    }
}

Here above is my code but when i compile it on command line like javac driver.java and then java driver it gives me error that could not load main class main ... please help me with sorting of this error .. this code btw contains file handling which is to be implemented later!

Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44

2 Answers2

1

I modified your code check the following code it works for me..

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){

    }
    }
}
Saveendra Ekanayake
  • 3,153
  • 6
  • 34
  • 44
  • its still giving error of couldnt load file demo :/ – mahnoor fatima Sep 06 '15 at 04:54
  • oh THANKYOU it's working but dont know what was the problem with it :/ – mahnoor fatima Sep 06 '15 at 05:01
  • You had package IO; statement, The declared package "IO" does not match excepted package. If you want to know about packages Go and have look this tutorial - https://docs.oracle.com/javase/tutorial/java/package/ . Next thing is best practice to use lowercase for package names. – Saveendra Ekanayake Sep 06 '15 at 05:06
0
  1. Are you locating the file correctly?
  2. Remove the package IO; and then compile it. It is compiled successfully. enter image description here
Hanzallah Afgan
  • 716
  • 6
  • 23