By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,996 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,996 IT Pros & Developers. It's quick & easy.

doesn't proceed for the static void main() method

100+
P: 281
Good Day All!
I have one problem and wish to consult......

I am using one program -mujava to create mutants.
I run the program and comes out this:
MyProgram.java class containts 'static void main() method.
Please note that mutants are not generated for the 'static void main()' method.


How to solve this problem or how am I supposed to pass arg (Image file name) as an input to MyProgram?
Maybe one you here have experienced the same, please advise...Thanks guys
Mar 5 '07 #1
Share this Question
Share on Google+
19 Replies


10K+
P: 13,264
Good Day All!
I have one problem and wish to consult......

I am using one program -mujava to create mutants.
I run the program and comes out this:
MyProgram.java class containts 'static void main() method.
Please note that mutants are not generated for the 'static void main()' method.

How to solve this problem or how am I supposed to pass arg (Image file name) as an input to MyProgram?
Maybe one you here have experienced the same, please advise...Thanks guys
Maybe if you post your code ...
Mar 5 '07 #2

100+
P: 281
Maybe if you post your code ...
Please check instructions on using ImageInfo program as below which I copied from the developer's website.
----------------------------------------------------------------------------------
Using ImageInfo from within a Java application or applet:
The image file can be any InputStream object or an instance of a class implementing DataInput (like RandomAccessFile). Here is some sample code on how to use the class:

Expand|Select|Wrap|Line Numbers
  1. ImageInfo ii = new ImageInfo();
  2. // in can be InputStream or RandomAccessFile (or DataInput)
  3. ii.setInput(in);
  4. /* if you want to know how many images there are in a file,
  5.    uncomment the following line; will slow down ImageInfo
  6.    with animated GIFs */
  7. //ii.setDetermineImageNumber(true);
  8.  
  9. // check does the actual work, you won't get results before
  10. // you have called it
  11. if (!ii.check())
  12. {
  13.   System.err.println("Not a supported image file format.");
  14. }
  15. else
  16. {
  17.  System.out.println(
  18.   ii.getFormatName() + ", " + 
  19.   ii.getMimeType() + ", " + 
  20.   ii.getWidth() + " x " + ii.getHeight() + " pixels, " + 
  21.   ii.getBitsPerPixel() + " bits per pixel, " + 
  22.   ii.getNumberOfImages() + " image(s).");
  23.   // there are other properties, check out the API documentation
  24. }
or Using ImageInfo as a command line program:
ImageInfo also has a main method that makes it a command line tool. Assuming that ImageInfo.class is in your classpath, giving the class to java with some file names as arguments will be sufficient. Here is an example call:

$ java ImageInfo test.jpg

thanks
Mar 5 '07 #3

100+
P: 281
just that I do not know what is the difference between those 2 options.
I used to run a program from command line.
Mar 5 '07 #4

10K+
P: 13,264
just that I do not know what is the difference between those 2 options.
I used to run a program from command line.
Running a java program always calls the java command regardless of whether it was called from the command line or from an interface program. How you supply the arguments depends on the interface program you are using.
Mar 5 '07 #5

100+
P: 281
Running a java program always calls the java command regardless of whether it was called from the command line or from an interface program. How you supply the arguments depends on the interface program you are using.
Thanks for the explanation.
If I wanted to skip command line argument and use from the class. Maybe I need to give image file name in the java program, is it possible for me to do so? I don't know, this is all because the program that I need to employ here doesn't support main() method . How am I supposed to do...
Mar 5 '07 #6

10K+
P: 13,264
Thanks for the explanation.
If I wanted to skip command line argument and use from the class. Maybe I need to give image file name in the java program, is it possible for me to do so? I don't know, this is all because the program that I need to employ here doesn't support main() method . How am I supposed to do...
What do you mean by
program that I need to employ here doesn't support main() method
?

You can hardcode the name of the image into the program or let the user supply the name to the program through the command or interface.
Mar 5 '07 #7

100+
P: 281
What do you mean by ?

You can hardcode the name of the image into the program or let the user supply the name to the program through the command or interface.
Alright, that's what I need isn't. Please give pointer on how to skip main() method if I want to hardcode the file name?
This is from my first post above:
[HTML]I am using one program -mujava to create mutants.
I run the program and comes out this:
MyProgram.java class containts 'static void main() method.
Please note that mutants are not generated for the 'static void main()' method.

How to solve this problem or how am I supposed to pass arg (Image file name) as an input to MyProgram?
Maybe one you here have experienced the same, please advise...Thanks guys[/HTML]
Mar 5 '07 #8

10K+
P: 13,264
Alright, that's what I need isn't. Please give pointer on how to skip main() method if I want to hardcode the file name?
This is from my first post above:
[HTML]I am using one program -mujava to create mutants.
I run the program and comes out this:
MyProgram.java class containts 'static void main() method.
Please note that mutants are not generated for the 'static void main()' method.

How to solve this problem or how am I supposed to pass arg (Image file name) as an input to MyProgram?
Maybe one you here have experienced the same, please advise...Thanks guys[/HTML]
You canoot skip the main. That is the method that kicks off your application. Post the code for your main method.
Mar 5 '07 #9

100+
P: 281
You canoot skip the main. That is the method that kicks off your application. Post the code for your main method.
Here is the main method for ImageInfo program that I downloaded from internet.
Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * To use this class as a command line application, give it either 
  3.      * some file names as parameters (information on them will be
  4.      * printed to standard output, one line per file) or call
  5.      * it with no parameters. It will then check data given to it
  6.      * via standard input.
  7.      * @param args the program arguments which must be file names
  8.      */
  9.     public static void main(String[] args) 
  10.         {
  11.         ImageInfo imageInfo = new ImageInfo();
  12.         imageInfo.setDetermineImageNumber(true);
  13.         boolean verbose = determineVerbosity(args);
  14.         if (args.length == 0) 
  15.                 {
  16.             run(null, System.in, imageInfo, verbose);
  17.         } else 
  18.                 {
  19.                     int index = 0;
  20.                     while (index < args.length) 
  21.                 {
  22.                         InputStream in = null;
  23.                         try {
  24.                                 String name = args[index++];
  25.                                 System.out.print(name + ";");
  26.                                 if (name.startsWith("http://")) 
  27.                                 {
  28.                                         in = new URL(name).openConnection().getInputStream();
  29.                                 } else 
  30.                                 {
  31.                                         in = new FileInputStream(name); //READ IMAGE FILE 
  32.                                 }
  33.                                 run(name, in, imageInfo, verbose);
  34.                                 in.close();
  35.  
  36.                         } catch (IOException e) 
  37.                         {
  38.                                 System.out.println(e);
  39.                                 try {
  40.                                         if (in != null) 
  41.                                         {
  42.                                                 in.close();
  43.                                         }
  44.                                 } catch (IOException ee) {
  45.                                 }
  46.                         }
  47.                     }
  48.         }
  49.     }
Mar 5 '07 #10

10K+
P: 13,264
Here is the main method for ImageInfo program that I downloaded from internet.
Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * To use this class as a command line application, give it either 
  3.      * some file names as parameters (information on them will be
  4.      * printed to standard output, one line per file) or call
  5.      * it with no parameters. It will then check data given to it
  6.      * via standard input.
  7.      * @param args the program arguments which must be file names
  8.      */
  9.     public static void main(String[] args) 
  10. {
  11.         ImageInfo imageInfo = new ImageInfo();
  12.         imageInfo.setDetermineImageNumber(true);
  13.         boolean verbose = determineVerbosity(args);
  14.         if (args.length == 0) 
  15. {
  16.             run(null, System.in, imageInfo, verbose);
  17.         } else 
  18. {
  19. int index = 0;
  20. while (index < args.length) 
  21. {
  22. InputStream in = null;
  23. try {
  24. String name = args[index++];
  25. System.out.print(name + ";");
  26. if (name.startsWith("http://")) 
  27. {
  28. in = new URL(name).openConnection().getInputStream();
  29. } else 
  30. {
  31. in = new FileInputStream(name); //READ IMAGE FILE 
  32. }
  33. run(name, in, imageInfo, verbose);
  34. in.close();
  35.  
  36. } catch (IOException e) 
  37. {
  38. System.out.println(e);
  39. try {
  40. if (in != null) 
  41. {
  42. in.close();
  43. }
  44. } catch (IOException ee) {
  45. }
  46. }
  47. }
  48.         }
  49.     }
Now all we need is the determineVerbosity function. Can you post that then?
Mar 5 '07 #11

100+
P: 281
Now all we need is the determineVerbosity function. Can you post that then?
Yes sure and sorry for this late reply (different time zone)
here is the determineVerbosity function, please advise:
Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * Run over String list, return false iff at least one of the arguments
  3.      * equals <code>-c</code>.
  4.      * @param args string list to check
  5.      */
  6.     private static boolean determineVerbosity(String[] args) 
  7.         {
  8.         if (args != null && args.length > 0) 
  9.                 {
  10.             for (int i = 0; i < args.length; i++) 
  11.                         {
  12.                 if ("-c".equals(args[i])) 
  13.                                 {
  14.                     return false;
  15.                 }
  16.             }
  17.         }
  18.         return true;
  19.     }
Mar 5 '07 #12

10K+
P: 13,264
Yes sure and sorry for this late reply (different time zone)
here is the determineVerbosity function, please advise:
Expand|Select|Wrap|Line Numbers
  1. /**
  2.      * Run over String list, return false iff at least one of the arguments
  3.      * equals <code>-c</code>.
  4.      * @param args string list to check
  5.      */
  6.     private static boolean determineVerbosity(String[] args) 
  7. {
  8.         if (args != null && args.length > 0) 
  9. {
  10.             for (int i = 0; i < args.length; i++) 
  11. {
  12.                 if ("-c".equals(args[i])) 
  13. {
  14.                     return false;
  15.                 }
  16.             }
  17.         }
  18.         return true;
  19.     }
I'm not sure what your program was supposed to do but to get it to work without supplying command line arguments you can do something like this:
Expand|Select|Wrap|Line Numbers
  1.  String name = "name of Image"; 
  2. ImageInfo imageInfo = new ImageInfo();
  3. imageInfo.setDetermineImageNumber(true);
  4. in = new FileInputStream(name); //READ IMAGE FILE 
  5. run(name, in, imageInfo, true); //For the last argument test with both true and false
  6.  
  7.  
Mar 6 '07 #13

100+
P: 281
I'm not sure what your program was supposed to do but to get it to work without supplying command line arguments you can do something like this:
Expand|Select|Wrap|Line Numbers
  1.  String name = "name of Image"; 
  2. ImageInfo imageInfo = new ImageInfo();
  3. imageInfo.setDetermineImageNumber(true);
  4. in = new FileInputStream(name); //READ IMAGE FILE 
  5. run(name, in, imageInfo, true); //For the last argument test with both true and false
  6.  
  7.  
Thanks. This program is basically get image file format, image resolution ...
Now I am trying with gif file format.
I have tried to compile the program & encountered this error (same error for both true and false) as below:

ImageInfo.java:1042: non-static variable in cannot be referenced from a static c
ontext
in = new FileInputStream(name); //READ IMAGE FILE
^
ImageInfo.java:1044: non-static variable in cannot be referenced from a static c
ontext
run(name, in, imageInfo, false);
^
2 errors

Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) 
  2.         {
  3.         String name = "testing.gif";
  4.                 ImageInfo imageInfo = new ImageInfo();
  5.         imageInfo.setDetermineImageNumber(true);
  6.  
  7.                 in = new FileInputStream(name); //READ IMAGE FILE 
  8.                 //imageInfo.setInput(in); 
  9.         run(name, in, imageInfo, false);
  10.  
  11.                /* boolean verbose = determineVerbosity(args);
  12.         if (args.length == 0) 
  13.                 {
  14.             run(null, System.in, imageInfo, verbose);
  15.         } else 
  16.                 {
  17.                     int index = 0;
  18.                     while (index < args.length) 
  19.                 {
  20.                         InputStream in = null;
  21.                         try {
  22.                                 String name = args[index++];
  23.                                 System.out.print(name + ";");
  24.                                 if (name.startsWith("http://")) 
  25.                                 {
  26.                                         in = new URL(name).openConnection().getInputStream();
  27.                                 } else 
  28.                                 {
  29.                                         in = new FileInputStream(name); //READ IMAGE FILE 
  30.                                 }
  31.                                 run(name, in, imageInfo, verbose);
  32.                                 in.close();
  33.  
  34.                         } catch (IOException e) 
  35.                         {
  36.                                 System.out.println(e);
  37.                                 try {
  38.                                         if (in != null) 
  39.                                         {
  40.                                                 in.close();
  41.                                         }
  42.                                 } catch (IOException ee) {
  43.                                 }
  44.                         }
  45.                     }
  46.         } */
  47.     }
Mar 6 '07 #14

10K+
P: 13,264
Thanks. This program is basically get image file format, image resolution ...
Now I am trying with gif file format.
I have tried to compile the program & encountered this error (same error for both true and false) as below:

ImageInfo.java:1042: non-static variable in cannot be referenced from a static c
ontext
in = new FileInputStream(name); //READ IMAGE FILE
^
ImageInfo.java:1044: non-static variable in cannot be referenced from a static c
ontext
run(name, in, imageInfo, false);
^
2 errors
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) 
  2. {
  3.         String name = "testing.gif";
  4. ImageInfo imageInfo = new ImageInfo();
  5.         imageInfo.setDetermineImageNumber(true);
  6.  
  7. in = new FileInputStream(name); //READ IMAGE FILE 
  8. //imageInfo.setInput(in); 
  9.         run(name, in, imageInfo, false);
  10.  
  11. /* boolean verbose = determineVerbosity(args);
  12.         if (args.length == 0) 
  13. {
  14.             run(null, System.in, imageInfo, verbose);
  15.         } else 
  16. {
  17. int index = 0;
  18. while (index < args.length) 
  19. {
  20. InputStream in = null;
  21. try {
  22. String name = args[index++];
  23. System.out.print(name + ";");
  24. if (name.startsWith("http://")) 
  25. {
  26. in = new URL(name).openConnection().getInputStream();
  27. } else 
  28. {
  29. in = new FileInputStream(name); //READ IMAGE FILE 
  30. }
  31. run(name, in, imageInfo, verbose);
  32. in.close();
  33.  
  34. } catch (IOException e) 
  35. {
  36. System.out.println(e);
  37. try {
  38. if (in != null) 
  39. {
  40. in.close();
  41. }
  42. } catch (IOException ee) {
  43. }
  44. }
  45. }
  46.         } */
  47.     }
Declare the InputStream in the main then. Add the line

Expand|Select|Wrap|Line Numbers
  1.  InputStream in = null;
as the first line of the main method.
Mar 6 '07 #15

100+
P: 281
Declare the InputStream in the main then. Add the line

Expand|Select|Wrap|Line Numbers
  1.  InputStream in = null;
as the first line of the main method.
Thanks a bunch. It works now without passing file name from command line.
but why need to declare in = null to solve the non-static variable in?
Mar 7 '07 #16

10K+
P: 13,264
Thanks a bunch. It works now without passing file name from command line.
but why need to declare in = null to solve the non-static variable in?
Read here to find out why non-static variables are not available in static contexts.
Mar 8 '07 #17

100+
P: 281
Read here to find out why non-static variables are not available in static contexts.
Because only static variables are accessible inside a static context. So main() is a static contexts and 'in' is not static variable. By initialize in to null, then it becomes static? please correct if I'm wrong. thanks to you.
Mar 9 '07 #18

10K+
P: 13,264
Because only static variables are accessible inside a static context. So main() is a static contexts and 'in' is not static variable. By initialize in to null, then it becomes static? please correct if I'm wrong. thanks to you.
Initializing it to null does not make it static. Declaring it inside main (which is static) is what makes it static.
Mar 9 '07 #19

100+
P: 281
Initializing it to null does not make it static. Declaring it inside main (which is static) is what makes it static.
Oh ...no wonder. thank you.
Mar 9 '07 #20

Post your reply

Sign in to post your reply or Sign up for a free account.