Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Command Line and two arguments

  1. #1
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Command Line and two arguments

    Simply put, i have to run my program from the command line

    My code is:

    public static void main( String[] args ) 
       {
     
          // check command-line arguments
          if ( args.length == 2 )
          {
             // get command-line arguments
             String databaseUserName = args[ 0 ];
             String databasePassword = args[ 1 ];
     
         // create new RestaurantBillCalculator
         RestaurantBillCalculator application = new RestaurantBillCalculator ( 
         databaseUserName, databasePassword );
     
          }
          else
          {
             System.out.println( "Usage: java " + 
                "RestaurantBillCalculator databaseUserName databasePassword" );
     
          }   
       } // end method main

    Now everything works in Netbeans but running it from the command line, i get an error message ".java uses unchecked and unsafe operations"

    I have added a bit more code to the code above
      for (int i = 0; i < args.length; i++) {
            System.out.println("args[" + i + "]: "
            + args[i]);
            }
    Just not sure how to run it from the command line, help please


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    What program are you trying to execute: javac or java
    It would help if you copied the full contents of the command prompt window and pasted it here.

    On Windows To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    Quote Originally Posted by Norm View Post
    What program are you trying to execute: javac or java
    It would help if you copied the full contents of the command prompt window and pasted it here.

    On Windows To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation. All rights reserved.

    C:\Users\Sean\Documents\NetBeansProjects\Restauran tBillCalculator\src>javac Rest
    aurantBillCalculator.java
    Note: RestaurantBillCalculator.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    C:\Users\Sean\Documents\NetBeansProjects\Restauran tBillCalculator\src>

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    Recompile with -Xlint:unchecked for details.
    The compiler is recommending that you use the -Xlint option to get a full description of the errors.
    For example:
    D:\Java\jdk1.7.0_45\bin\javac.exe -cp . -Xlint TestCode18.java
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    So how do i write that in the command line? the way you have it exactly or what?

    --- Update ---

    If this is just a warning, why wont my code compile in the command line? i have 7 warnings but no errors in my netbeans project, all the warnings are "exception.printStackTrace

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    Please copy the full text of the error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    There is no errors, this is what i don't understand! the program runs fine in Netbeans but when i run it at the command line, it asks to recompile with -Xlint

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    The IDE is ignoring the warnings. That can lead to problems when some of the warnings really effect how the code runs. For example try this statement: if( 2>1); using the -Xlint option gives this warning:
    if(1 > 2); // warning: [empty] empty statement after if
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    SeanyC (September 14th, 2014)

  10. #9
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    Quote Originally Posted by Norm View Post
    The IDE is ignoring the warnings. That can lead to problems when some of the warnings really effect how the code runs. For example try this statement: if( 2>1); using the -Xlint option gives this warning:
    if(1 > 2); // warning: [empty] empty statement after if
    Okay i got the list of what is wrong, and i get these warnings below

    RestaurantBillCalculator.java:308: warning: [unchecked] unchecked call to addIte
    m(E) as a member of the raw type JComboBox

    RestaurantBillCalculator.java:569: warning: [unchecked] unchecked call to add(E)
    as a member of the raw type ArrayList
    billItems.add(( String ) beverageJComboBox.getSelectedItem() );

    I believe i would have to go generic here?

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    Yes, those look like missing generic code.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #11
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    Quote Originally Posted by Norm View Post
    Yes, those look like missing generic code.
    CAn you help me out with it? the first one i have my combobox called:
    beverageJComboBox = new javax.swing.JComboBox();

    Next one is:
    private void beverageJComboBoxItemStateChanged( java.awt.event.ItemEvent event )
       {
          // select an item   
          if ( event.getStateChange() == java.awt.event.ItemEvent.SELECTED )   
          {   
             billItems.add(( String ) beverageJComboBox.getSelectedItem() );   
          }

  13. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    If you don't understand my answer, don't ignore it, ask a question.

  14. #13
    Member
    Join Date
    Sep 2014
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Command Line and two arguments

    Quote Originally Posted by Norm View Post
    On it thanks

    --- Update ---

    Quote Originally Posted by Norm View Post
    Hey can you you help me out with this one below, its the only one im stuck on and its doing my head in?
    // set up beverageJComboBox
          beverageJComboBox = new javax.swing.JComboBox();
          beverageJComboBox.setEnabled( true ); 
          beverageJComboBox.setBounds( 88, 24, 128, 25 );
          menuItemsJPanel.add( beverageJComboBox );
          beverageJComboBox.addItemListener(
             new java.awt.event.ItemListener()  // anonymous inner class
             {
                // event handler called when item in beverageJComboBox
                // is selected
                 @Override
                public void itemStateChanged( java.awt.event.ItemEvent event )
                {
                   beverageJComboBoxItemStateChanged( event );
                }
             } // end anonymous inner class
          ); // end addItemListener
     
          // add items to beverageJComboBox
          beverageJComboBox.addItem( "" );   
          loadCategory( "Beverage", beverageJComboBox );
    I have tried <String> <Number> <Integer>

  15. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Command Line and two arguments

    I have tried
    Please post the code showing what you have tried and the error messages you get.
    The posted code does not show the definition for the variable: beverageJComboBox.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Arrays , command line arguments
    By Jad_Asmar in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 30th, 2013, 11:25 AM
  2. File Processing- Command Line Arguments
    By TSSF44 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: November 21st, 2013, 07:52 PM
  3. Help understanding Command-Line Arguments
    By Truck35 in forum Collections and Generics
    Replies: 1
    Last Post: December 13th, 2012, 06:16 PM
  4. command line arguments
    By rizla in forum Member Introductions
    Replies: 3
    Last Post: December 12th, 2010, 11:14 PM
  5. Multi-Valued Command Line Arguments
    By joey86 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 29th, 2009, 11:19 AM

Tags for this Thread