Results 1 to 4 of 4

Thread: Error

  1. #1
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default Error

    Hi, I'm creating a class in Java named CommandLineInterface. when my program run in Netbeans there's no ERROR message. but when i trying to run in CommandLine (CMD) i got this ERROR message:
    Java Code:
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
    	at Mekonah.Core.CommandLineInterface.CommandLineInterface.getParameterTPF(CommandLineInterface.java:100)
    	at Main.Main.testCLI(Main.java:1791)
    	at Main.Main.main(Main.java:89)
    Java Code:
    public class CommandLineInterface {
        
        public void getParameterTRF(String args[]){
    	//Format: -RF=\"C:\Temp\file.rc"
            StringParser parser = new StringParser();
            ChunkParser cp = new ChunkParser(parser, new Comment(Comment.CPPName));
            int fetchItemState = 1;
            boolean terminate = false;
            boolean errorOcurred = false;
            StringBuffer fetchKind = new StringBuffer();
            String currentFetch = null;
            String errorType = null;
    
            for(int ctr=0; ctr<args.length && !errorOcurred; ctr++){
                parser.setCurrentIndex(0);
                while(!terminate){
                    currentFetch = cp.getValidItem(args[ctr], fetchKind, Keywords.Quoted_C_String);
                    switch(fetchItemState){
                        case 1:
                            if(cp.isFetchKindDash(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_DASH_EXPECTED");
                            }
                            break;
                        case 2:
                            if(cp.isFetchKindResourceWord(fetchKind.toString())&&
                                    currentFetch.equals("TRF")){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_RESOURCEWORD_EXPECTED");
                            }
                            break;
                        case 3:
                            if(cp.isFetchKindEquals(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_EQUALS_EXPECTED");
                            }
                            break;
                        case 4:
                            if(cp.isFetchKind_C_QuotedString(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_QUOTED_VALUE_EXPECTED");
                            }
                            terminate = true;
                            break;
    
                    }
                    if(errorOcurred){
                        terminate = true;
                        System.out.print(errorType);
                    }
                    else{
                        System.out.print(currentFetch);
                    }
    
                }//end of while(!terminate)
                System.out.println();
            }//end of for(int ctr=0; ctr<args.length && errorOcurred; ctr++
        }//end of getParameterTRF
    
        
        public void getParameterTPF(String args[]){
    	//Format: -RF=\"C:\Temp\file.rc"
            StringParser parser = new StringParser();
            ChunkParser cp = new ChunkParser(parser, new Comment(Comment.CPPName));
            int fetchItemState = 1;
            boolean terminate = false;
            boolean errorOcurred = false;
            StringBuffer fetchKind = new StringBuffer();
            String currentFetch = null;
            String errorType = null;
    
            //for(int ctr=0; ctr<args.length && !errorOcurred; ctr++){
                parser.setCurrentIndex(0);
                while(!terminate){
                    currentFetch = cp.getValidItem(args[1], fetchKind, Keywords.Quoted_C_String);
                    switch(fetchItemState){
                        case 1:
                            if(cp.isFetchKindDash(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_DASH_EXPECTED");
                            }
                            break;
                        case 2:
                            if(cp.isFetchKindResourceWord(fetchKind.toString())&&
                                    currentFetch.equals("TPF")){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_RESOURCEWORD_EXPECTED");
                            }
                            break;
                        case 3:
                            if(cp.isFetchKindEquals(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_EQUALS_EXPECTED");
                            }
                            break;
                        case 4:
                            if(cp.isFetchKind_C_QuotedString(fetchKind.toString())){
                                fetchItemState++;
                            }
                            else{
                                errorOcurred = true;
                                errorType = new String("ERROR_QUOTED_VALUE_EXPECTED");
                            }
                            terminate = true;
                            break;
    
                    }
                    if(errorOcurred){
                        terminate = true;
                        System.out.print(errorType);
                    }
                    else{
                        System.out.print(currentFetch);
                    }
    
                }//end of while(!terminate)
                System.out.println();
            //}//end of for(int ctr=0; ctr<args.length && errorOcurred; ctr++
        }//end of getParameterTPF
    thanks for helps in advance
    Last edited by mlibot; 03-01-2010 at 04:03 AM.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    Well, did you provide any arguments on the command line?

    Edit: And, if you didn't, you should also change your app to check for this and exit gracefully.
    Last edited by masijade; 03-01-2010 at 08:13 AM.

  3. #3
    mlibot is offline Member
    Join Date
    Sep 2009
    Posts
    44
    Rep Power
    0

    Default

    Yes i provide an arguments in command line.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    10

    Default

    One? Or more? Also, why did you comment the for loop, then hard code to use the second provided argument over and over again?

Similar Threads

  1. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  2. Replies: 1
    Last Post: 10-26-2009, 05:38 PM
  3. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  4. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •