Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Parsing argv Problem :-(

Thread view: 
Ess - 05 Apr 2005 17:30 GMT
Hi,

My main method starts like this:

------------------------------
 public static void main(String[] args)
   {
   if (args.length > 1)
    {
         try
        {
           System.err.println("hello");
               
              JFrame frame = new Task3(args);  //doesn't like this bit
              frame.pack();
-----------------------------------

Task3 function starts like this:

-----------------------------------
   
   public Task3 (String[] imageFiles) throws IOException,
ImageDecoderException
   {
       super("Task1: Now comparing " + imageFiles[0] + " to other
images ...");
-----------------------------------

I hoped that the string values in args would be parsed into the array
imageFiles, but it doesn't seem to work. :-(

I've tried using argv.

Please could you tell me the problem. :-)

Thanks in advance,
Ess
Knute Johnson - 05 Apr 2005 18:12 GMT
> Hi,
>
[quoted text clipped - 33 lines]
> Thanks in advance,
> Ess

Well hope is a great virtue but it is not going to help you write
compilable Java code.

I would really like to help you with your problem but since you didn't
provide any compilable code or even any error messages (compile or
runtime) I have no idea what your problem could be but I will show you
one way to get your command line arguments into your code.  The
arguments are an array of Strings.  You will note that I am creating a
new instance of the class test4.  If you want to pass the arguments to a
method and not a constructor the code would be different.

public class test4 {
    public test4(String[] cmdLineStrs) {
        for (int i=0; i<cmdLineStrs.length; i++)
            System.out.println(cmdLineStrs[i]);
    }

    public static void main(String[] args) {
        new test4(args);
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Ess - 06 Apr 2005 18:53 GMT
Hi,

Thank u for your replies. My problem wasn't with parsing argv, but
that I have other arrays being indexed at illegal locations!

Sorry for hassling u guys.

Have a good day,
Ess

> > Hi,
> >
[quoted text clipped - 55 lines]
>      }
> }
Andy Flowers - 05 Apr 2005 18:15 GMT
> Hi,
>
[quoted text clipped - 6 lines]
>
>       JFrame frame = new Task3(args);  //doesn't like this bit

What is the error, I assume from your post it is a compile time error ? or
is it s runtime exception ?

Is Task3 a subclass of JFrame ?
Ess - 06 Apr 2005 00:01 GMT
Hi,

My error is a runtime one:

java.lang.ArrayIndexOutOfBoundsException: 2

I understand this has something to do with my array being too small,
but I can't see where the problem is.

Task3 is a subclass of JFrame. Here is some code of the program:

------------------------------------------------------
public class Task3 extends JFrame
{

//class variables
   
   public Task3 (String[] imageFiles) throws IOException,
ImageDecoderException
   {
       super("Task1: Now comparing " + imageFiles[0] + " to other
images ...");
 
....
....
------------------------------------------------------

Than you again,
Ess

> > Hi,
> >
[quoted text clipped - 11 lines]
>
> Is Task3 a subclass of JFrame ?
Andy Flowers - 06 Apr 2005 07:52 GMT
> Hi,
>
> My error is a runtime one:
>
> java.lang.ArrayIndexOutOfBoundsException: 2

Your clue is in the number after the exception name '2'. This is the array
index you are attempting to access somewhere in your code and this is beyond
the end of the array.

In main you check if imageFiles[0] contains an element, do you do further
checks elsewhere ?

Perhaps you use  imageFiles[2] elsewhere ?

Perhaps you could post a fuller example of your Task3(String[]...)
constructor ?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.