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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shana07
    Contributor
    • Jan 2007
    • 280

    #1

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

    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shana07
    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 ...

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #3
      Originally posted by r035198x
      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 RandomAccessFil e). Here is some sample code on how to use the class:

      Code:
      ImageInfo ii = new ImageInfo();
      // in can be InputStream or RandomAccessFile (or DataInput)
      ii.setInput(in);
      /* if you want to know how many images there are in a file,
         uncomment the following line; will slow down ImageInfo
         with animated GIFs */
      //ii.setDetermineImageNumber(true);
      
      // check does the actual work, you won't get results before
      // you have called it
      if (!ii.check())
      {
        System.err.println("Not a supported image file format.");
      }
      else
      {
       System.out.println(
        ii.getFormatName() + ", " + 
        ii.getMimeType() + ", " + 
        ii.getWidth() + " x " + ii.getHeight() + " pixels, " + 
        ii.getBitsPerPixel() + " bits per pixel, " + 
        ii.getNumberOfImages() + " image(s).");
        // there are other properties, check out the API documentation
      }
      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

      Comment

      • shana07
        Contributor
        • Jan 2007
        • 280

        #4
        just that I do not know what is the difference between those 2 options.
        I used to run a program from command line.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by shana07
          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.

          Comment

          • shana07
            Contributor
            • Jan 2007
            • 280

            #6
            Originally posted by r035198x
            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...

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by shana07
              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.

              Comment

              • shana07
                Contributor
                • Jan 2007
                • 280

                #8
                Originally posted by r035198x
                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]

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by shana07
                  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.

                  Comment

                  • shana07
                    Contributor
                    • Jan 2007
                    • 280

                    #10
                    Originally posted by r035198x
                    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.
                    Code:
                    /**
                    	 * To use this class as a command line application, give it either 
                    	 * some file names as parameters (information on them will be
                    	 * printed to standard output, one line per file) or call
                    	 * it with no parameters. It will then check data given to it
                    	 * via standard input.
                    	 * @param args the program arguments which must be file names
                    	 */
                    	public static void main(String[] args) 
                            {
                    		ImageInfo imageInfo = new ImageInfo();
                    		imageInfo.setDetermineImageNumber(true);
                    		boolean verbose = determineVerbosity(args);
                    		if (args.length == 0) 
                                    {
                    			run(null, System.in, imageInfo, verbose);
                    		} else 
                                    {
                                        int index = 0;
                                        while (index < args.length) 
                                    {
                                            InputStream in = null;
                                            try {
                                                    String name = args[index++];
                                                    System.out.print(name + ";");
                                                    if (name.startsWith("http://")) 
                                                    {
                                                            in = new URL(name).openConnection().getInputStream();
                                                    } else 
                                                    {
                                                            in = new FileInputStream(name); //READ IMAGE FILE 
                                                    }
                                                    run(name, in, imageInfo, verbose);
                                                    in.close();
                                                    
                                            } catch (IOException e) 
                                            {
                                                    System.out.println(e);
                                                    try {
                                                            if (in != null) 
                                                            {
                                                                    in.close();
                                                            }
                                                    } catch (IOException ee) {
                                                    }
                                            }
                                        }
                    		}
                    	}

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by shana07
                      Here is the main method for ImageInfo program that I downloaded from internet.
                      Code:
                      /**
                      	 * To use this class as a command line application, give it either 
                      	 * some file names as parameters (information on them will be
                      	 * printed to standard output, one line per file) or call
                      	 * it with no parameters. It will then check data given to it
                      	 * via standard input.
                      	 * @param args the program arguments which must be file names
                      	 */
                      	public static void main(String[] args) 
                      {
                      		ImageInfo imageInfo = new ImageInfo();
                      		imageInfo.setDetermineImageNumber(true);
                      		boolean verbose = determineVerbosity(args);
                      		if (args.length == 0) 
                      {
                      			run(null, System.in, imageInfo, verbose);
                      		} else 
                      {
                      int index = 0;
                      while (index < args.length) 
                      {
                      InputStream in = null;
                      try {
                      String name = args[index++];
                      System.out.print(name + ";");
                      if (name.startsWith("http://")) 
                      {
                      in = new URL(name).openConnection().getInputStream();
                      } else 
                      {
                      in = new FileInputStream(name); //READ IMAGE FILE 
                      }
                      run(name, in, imageInfo, verbose);
                      in.close();
                       
                      } catch (IOException e) 
                      {
                      System.out.println(e);
                      try {
                      if (in != null) 
                      {
                      in.close();
                      }
                      } catch (IOException ee) {
                      }
                      }
                      }
                      		}
                      	}
                      Now all we need is the determineVerbos ity function. Can you post that then?

                      Comment

                      • shana07
                        Contributor
                        • Jan 2007
                        • 280

                        #12
                        Originally posted by r035198x
                        Now all we need is the determineVerbos ity function. Can you post that then?
                        Yes sure and sorry for this late reply (different time zone)
                        here is the determineVerbos ity function, please advise:
                        Code:
                        /**
                        	 * Run over String list, return false iff at least one of the arguments
                        	 * equals <code>-c</code>.
                        	 * @param args string list to check
                        	 */
                        	private static boolean determineVerbosity(String[] args) 
                                {
                        		if (args != null && args.length > 0) 
                                        {
                        			for (int i = 0; i < args.length; i++) 
                                                {
                        				if ("-c".equals(args[i])) 
                                                        {
                        					return false;
                        				}
                        			}
                        		}
                        		return true;
                        	}

                        Comment

                        • r035198x
                          MVP
                          • Sep 2006
                          • 13225

                          #13
                          Originally posted by shana07
                          Yes sure and sorry for this late reply (different time zone)
                          here is the determineVerbos ity function, please advise:
                          Code:
                          /**
                          	 * Run over String list, return false iff at least one of the arguments
                          	 * equals <code>-c</code>.
                          	 * @param args string list to check
                          	 */
                          	private static boolean determineVerbosity(String[] args) 
                          {
                          		if (args != null && args.length > 0) 
                          {
                          			for (int i = 0; i < args.length; i++) 
                          {
                          				if ("-c".equals(args[i])) 
                          {
                          					return false;
                          				}
                          			}
                          		}
                          		return true;
                          	}
                          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:
                          Code:
                           String name = "name of Image"; 
                          ImageInfo imageInfo = new ImageInfo();
                          imageInfo.setDetermineImageNumber(true);
                          in = new FileInputStream(name); //READ IMAGE FILE 
                          run(name, in, imageInfo, true); //For the last argument test with both true and false

                          Comment

                          • shana07
                            Contributor
                            • Jan 2007
                            • 280

                            #14
                            Originally posted by r035198x
                            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:
                            Code:
                             String name = "name of Image"; 
                            ImageInfo imageInfo = new ImageInfo();
                            imageInfo.setDetermineImageNumber(true);
                            in = new FileInputStream(name); //READ IMAGE FILE 
                            run(name, in, imageInfo, true); //For the last argument test with both true and false
                            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

                            Code:
                            public static void main(String[] args) 
                                    {
                            		String name = "testing.gif";
                                            ImageInfo imageInfo = new ImageInfo();
                            		imageInfo.setDetermineImageNumber(true);
                                            
                                            in = new FileInputStream(name); //READ IMAGE FILE 
                                            //imageInfo.setInput(in); 
                            		run(name, in, imageInfo, false);
                                            
                                           /* boolean verbose = determineVerbosity(args);
                            		if (args.length == 0) 
                                            {
                            			run(null, System.in, imageInfo, verbose);
                            		} else 
                                            {
                                                int index = 0;
                                                while (index < args.length) 
                                            {
                                                    InputStream in = null;
                                                    try {
                                                            String name = args[index++];
                                                            System.out.print(name + ";");
                                                            if (name.startsWith("http://")) 
                                                            {
                                                                    in = new URL(name).openConnection().getInputStream();
                                                            } else 
                                                            {
                                                                    in = new FileInputStream(name); //READ IMAGE FILE 
                                                            }
                                                            run(name, in, imageInfo, verbose);
                                                            in.close();
                                                            
                                                    } catch (IOException e) 
                                                    {
                                                            System.out.println(e);
                                                            try {
                                                                    if (in != null) 
                                                                    {
                                                                            in.close();
                                                                    }
                                                            } catch (IOException ee) {
                                                            }
                                                    }
                                                }
                            		} */
                            	}

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by shana07
                              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
                              Code:
                              public static void main(String[] args) 
                              {
                              		String name = "testing.gif";
                              ImageInfo imageInfo = new ImageInfo();
                              		imageInfo.setDetermineImageNumber(true);
                               
                              in = new FileInputStream(name); //READ IMAGE FILE 
                              //imageInfo.setInput(in); 
                              		run(name, in, imageInfo, false);
                               
                              /* boolean verbose = determineVerbosity(args);
                              		if (args.length == 0) 
                              {
                              			run(null, System.in, imageInfo, verbose);
                              		} else 
                              {
                              int index = 0;
                              while (index < args.length) 
                              {
                              InputStream in = null;
                              try {
                              String name = args[index++];
                              System.out.print(name + ";");
                              if (name.startsWith("http://")) 
                              {
                              in = new URL(name).openConnection().getInputStream();
                              } else 
                              {
                              in = new FileInputStream(name); //READ IMAGE FILE 
                              }
                              run(name, in, imageInfo, verbose);
                              in.close();
                               
                              } catch (IOException e) 
                              {
                              System.out.println(e);
                              try {
                              if (in != null) 
                              {
                              in.close();
                              }
                              } catch (IOException ee) {
                              }
                              }
                              }
                              		} */
                              	}
                              Declare the InputStream in the main then. Add the line

                              Code:
                               InputStream in = null;
                              as the first line of the main method.

                              Comment

                              Working...