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
19 2741
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 ...
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: - 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
just that I do not know what is the difference between those 2 options.
I used to run a program from command line.
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.
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...
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.
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]
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.
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. - /**
-
* 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) {
-
}
-
}
-
}
-
}
-
}
Here is the main method for ImageInfo program that I downloaded from internet. - /**
-
* 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 determineVerbosity function. Can you post that then?
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: - /**
-
* 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;
-
}
Yes sure and sorry for this late reply (different time zone)
here is the determineVerbosity function, please advise: - /**
-
* 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: - 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
-
-
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: - 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 - 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) {
-
}
-
}
-
}
-
} */
-
}
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 - 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
as the first line of the main method.
Declare the InputStream in the main then. Add the line
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?
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.
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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
|
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...
|
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....
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |