473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

281 100+
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
19 2741
r035198x
13,262 8TB
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
shana07
281 100+
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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
r035198x
13,262 8TB
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
shana07
281 100+
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

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

Similar topics

4
by: AckbarJedi | last post by:
Given this very basic program: public class Blah { public static void main (String args) { doStuff(); //Calls the method doStuff }//Closes main
12
by: Yu | last post by:
I have found that the static object is initialised at the time when the shared libary is loaded. The initialisation caused the invocation of the constructor. May I know of any way that I can...
0
by: James Thurley | last post by:
I'm trying to dynamically compile assemblies and cache them to disk, which seems to work fine. When the data I'm compiling from changes, I want to re-generate the assembly and use the new version....
3
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects...
16
by: Ed Sutton | last post by:
I use a mutex to disallow starting a second application instance. This did not work in a release build until I made it static member of my MainForm class. In a debug build, first instance got...
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
0
by: Owen | last post by:
Hello everyone, I am using VS.NET 2003(Trandition Chinese) Edition, and httpLook software for checking http requests. I found a problem that the following programs don't really "POST". These...
6
by: Andre Ranieri | last post by:
Hello everyone, I'm wondering if I could get some advice on the best way to build the user interface depicted in this diagram: http://www.senske.com/images/winforms_layout.jpg The gray areas...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.