0

Any ideas why I keep getting a runtime error with this? I am very new, please go easy on me. I am trying to accept user input to generate a very simple encryption of a file. I am getting an error:

Static Error: This class does not have a static void main method accepting String[].

I have a main methor accepting string[]! I am lost. Any suggestions?

import java.io.*;
import java.util.Scanner;


public class Encryption
{

public static void main(String[] args, String existing, String encrypted) throws IOException
   {

   boolean eof = false;
   int key = 10;

   Scanner scan = new Scanner(System.in);
   key = scan.nextInt();

 /* Your encryption program should work like a filter, reading the contents of one file...
 */

   FileInputStream inStream = new FileInputStream(existing);
   DataInputStream inFile = new DataInputStream(inStream);

   FileOutputStream outStream = new FileOutputStream(encrypted);
   DataOutputStream outFile = new DataOutputStream(outStream);

   while (!eof)
   {
      try
      {
         byte input = inFile.readByte();

 /* modifying the data into a code...
  */            
          input += key;

 /* and then writing the coded contents out to a second file.
 * The second file will be a version of the first file, but written in a secret code.
 */            

      outFile.writeByte(input);
      }
      catch (EOFException e)
      {
         eof = true;
      }
   }
  }
}
d.r.
  • 11

3 Answers3

0

Your main method needs to take only String[] args. In your example you have encrypted and existing as Strings. The JVM will not recognize your main method if it has different input parameters.

So instead of

main(String[] args, String existing, String encrypted)

you should have

main(String[] args)

Then get the two arguments that you need from the args array and assign them to Strings with the same name. For example:

String existing = args[0];
String encrypted = args[1];

You could also collect these with a foreach loop.

Jason D
  • 8,023
  • 10
  • 33
  • 39
0

Your method is accepting String[], true, but it is also accepting other arguments as well, notably String and String.

Your main method must have the signature public static void main(String args[]).

In Java, methods are called according their method signature. Lots of information can be found online about this, but essentially methods are called according to both their name and the parameters they take. This means that a method myMethod(int) and myMethod(String) and myMethod(int, int) are all different methods and can be called separately (this is incidentally referred to as method overloading).

Brent C
  • 833
  • 1
  • 9
  • 15
0

Your main method needs to be defined with a parameter list consisting only of String[] args. You have also passed String existing, String encrypted which means the JVM ignores or overlooks your main method.

Take a look at this post to understand how to pass those arguments using the args param. What is "String args[]"? parameter in main method Java

Community
  • 1
  • 1
gimg1
  • 1,121
  • 10
  • 24