Whats wrong - help pls

I have a main method which accepts/expects the username and password as its arguments.
The problem when i run this code is
instead of displaying the error message
System.err.println("Username not present");
the program gives the following runtime error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at Banni11sear.main(Compiled Code)
I know i can catch this using but i want to display my own error message.I don't know why the following code is giving runtime error instead of displaying the "username not present"
any help is appreciated
-sagarika
* This is the main method.
* @par String[] args. The main method expects the
* username and password as arguments.
* The format would be
* java <filename> -u username -p password
public static void main(String[] args) {
if (args[1] == null) {
System.err.println("Username not present");
System.exit(1);
if(args[3] == null) {
System.err.println("Password not given");
System.exit(1);
Sample sample = new Sample(args[1], args[3]);
sample.close();
}

and i posted a reply and fixed code in another one...
http://forum.java.sun.com/thread.jsp?thread=314204&forum=48&message=1262390
please do not cross-post!

Similar Messages

  • Tomcat doesn't report which line is wrong,help,pls!!

    when I use tomcat 4.0, it's can report which line is wrong, and also
    ere forexample
    ^
    you know , above ^ is where wrong. But when I update to tomcat 5.5, it's can't report exactly which line is wrong in jsp file! Yeah,it's still report someline is wrong, but when i check the jsp file, that's line has nothing. OK, then i change some code, but still report that line is wrong.
    it's really drive me crazy. And no ^, tell me which part is wrong. I really don't want to setup tomcat 4.0 again, it's bad feeling.What should i do?

    OK.just example:
    <%@ page import="java.sql.*" %>
    <%
    String connectionURL = "jdbc:mysql://localhost:3306/test";
    Connection connection = null;
    Statement statement = null;
    %>
    <html><body>
    <%
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL, "root", "dirdir");
    String sql;
    &#12288;&#12288;sql ="insert into pet(name,owner) values (?,?)";
    &#12288;&#12288;PreparedStatement ps=connection.prepareStatement(sql);
    &#12288;&#12288;ps.setString(1,"lei");
    &#12288;&#12288;ps.setString(2,"dog");
    %>
    <%
    ResultSet rs = ps.executeQuery();
    &#12288;&#12288;int c = ps.executeUpdate();
    %>
    Error report:
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 8 in the jsp file: /insert.jsp
    Generated servlet error:
    Syntax error on tokens, delete these tokens
    An error occurred at line: 8 in the jsp file: /insert.jsp
    Generated servlet error:
    Syntax error on tokens, delete these tokens
    An error occurred at line: 8 in the jsp file: /insert.jsp
    Generated servlet error:
    Syntax error on tokens, delete these tokens
    An error occurred at line: 8 in the jsp file: /insert.jsp
    Generated servlet error:
    Syntax error on tokens, delete these tokens
    An error occurred at line: 17 in the jsp file: /insert.jsp
    Generated servlet error:
    Syntax error on tokens, delete these tokens
         org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
         org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
         org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
    i don't care what's error in the code, I just want to know why tomcat's error report doesn't tell me which line wrong exactly! And no "^" tell me which part is wrong. now report line number is the line where <% is.

  • Z1 Bug or what? HELP PLS

    Hi people, 
    I need help urgently, for some reason when my phone is left alone for more than 6 hours or so (such as when im sleeping while im charging it) my phone becomes unable to listen to play music while being on silent or vibrate mode. When i open the walkman, and try to raise the volume, it just shows me the silent icon. In this "mode:" i can only listen when not on silent/vibrate and to fix it i have to restart my phone... This is really getting on my nerves as i have to keep on restarting my phone, need help urgently.

    Boot the phone in safe mode,see if the same occurs:
    http://talk.sonymobile.com/t5/FAQ/How-to-boot-your-phone-into-safe-mode/m-p/348008
    All we have to decide is what to do with the time that is given to us - J.R.R. Tolkien

  • HT1386 i deleted some songs from my iphone 4. now when i try to re-add them to my phones itunes, they wont add. whats wrong? new songs add. but not the old ones! help please

    i deleted some songs from my iphone 4. now when i try to re-add them to my phones itunes, they wont add. whats wrong? new songs add. but not the old ones! help please

    Hey renie1515,
    Thanks for using Apple Support Communities.
    When you download past purchases on an iOS device or computer, that device or computer becomes associated with your Apple ID. This article describes how to manage these associations.
    iTunes Store: Associating a device or computer to your Apple ID
    http://support.apple.com/kb/ht4627
    Once a device or computer is associated with your Apple ID, you cannot associate that device or computer with another Apple ID for 90 days.
    Note: Removing a device from your Apple ID does not override the 90-day timer. You must wait 90 days from the day the device was first associated with your Apple ID before it can be associated with another Apple ID.
    Have a nice day,
    Mario

  • I made a mistake. i installed windows using boot camp without os x lion dvd. what should i do? help pls

    i made a mistake. i installed windows using boot camp without os x lion dvd. what should i do? help pls
    Re: can i install windows for pc on my mac or do i need the windows for mac? 

    There is no Lion DVD. Start Boot Camp Assistant and select the menu item to download the Windows Support Software.
    Read and follow the Boot Camp Installation Guide. http://manuals.info.apple.com/en_US/boot_camp_install-setup_10.7.pdf

  • Oh man i dont know whats wrong.... plz help urgent...

    i dont know whats wrong with my n900.... a couple of weeks before i tried to install nitroid gingerbread on my n900.... i did exactly what it said it was almost complete but the last step didnt complete so i left it like that..... i was using my mobile fine until one day i restarted my phone... when  it started it showed me 2 options (dont remember what the options were) although the 2nd one was power kernel something like that.... i chose 1st option after that it turned off when i startit again only nokia logo comes and it turns off by himself.... i thinki bricked my fone... but y didnt it happen when i was trying to install nitroid... plz help any way to fix it....
    P.S. I cant flash it either.. it doesnt go to usb mode anymore neither does it charge....
    Solved!
    Go to Solution.

    you could try to do the commands in flasher, connect the device while it is off and holding the U button down and see if the flasher will see it.

  • My iPad no longer puts out sound it was in my backpack will it was raining and don't know if that's what caused it pls help

    My iPad no longer puts out sound it was in my backpack will it was raining and don't know if that's what caused it pls help

    A possible cause is a problem with the file places.sqlite that stores the bookmarks and the history.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    *https://support.mozilla.org/kb/Bookmarks+not+saved#w_fix-the-bookmarks-file
    You can also try to repair the places database with this extension:
    *https://addons.mozilla.org/firefox/addon/places-maintenance/

  • I have been trying to open itunes that has already been installed. But, the thing is it never opens and when i do right click and trouble shoot also, it doesnt open. I dont whats wrong with itunes and my comp is 64 bit windows 7. Can somebody please help

    I have been trying to open itunes that has already been installed. But, the thing is it never opens and when i do right click and trouble shoot also, it doesnt open. I dont whats wrong with itunes and my comp is 64 bit windows 7. Can somebody please help

    no its 64 bit version of itunes. Can you please help me. I am not able to sync my iphone.

  • Help Me With This Error I Don't Know What Wrong With It Please

    Whats wrong with my program every time I compile it it has an error saying that ')' expected I don't know whats wrong with it someone help me, thank you.
    //   Robins.java
    //   Demonstrate the different behaviors of the + operator
    public class Robins
        // main prints some expressions using the + operator
        public static void main (String[] args)
         System.out.println ("Ten robins plus " + 13 canaries is + 23 birds);
    }

    System.out.println ("Ten robins plus " + "13 canaries is" + "23 birds");You can't type regular text that is not inside of " and " or it will be treated as a number / variable / something else.

  • After installing new OS i can't type a login and password because the font is not supported. DO NOT KNOW WHAT TO DO!!!!HELP PLS?!

    after installing new OS i can't type a login and password because the font is not supported. DO NOT KNOW WHAT TO DO!!!!HELP PLS?!

    Hello Pete from another old guy,
    It sounds like you have an older iMac than the 2006 and newer model this forum covers. The problem is that, in 2006, Apple changed from PowerPC to Intel processors and third-party developers soon stopped making new software for the older processors. That's why you cannot upgrade Flash player--the current version requires a Mac the "2006 and later" processor.
    However, not having a current version of FlashPlayer should not affect your ability to download. If you try downloading, do you get an error message or does something else happen?
    Do you have another web browser like FireFox or Camino on your computer?
    but would love to get my MAC back up to date and running right.
    Well, "running right" may be doable but "up to date" may not be. You are already at as high a Mac OS level that a pre-2006 Mac can use.  We need to pin down your variant to make recommendations. From your Apple menu at the left end of the menu bar, do "About this Mac":
    That brings up this window:
    Let us know what yours say for "processor." The two choices are "PowerPC" as in the example, or "Intel." If you  have an Intel processor, you have more options available.
    Awaiting your report,
    Allan

  • Yes my ipod touch 2nd generation 8gb wont turn on, i was on my way to my next class at school and it just randomly shut off, its been off ever sense and i don't know whats wrong, it had a good charge and i don't know what to do please help me

    My ipod touch 2nd generation 8gb wont turn on, i was on my way to my next class at school and it just randomly shut off, its been off ever sense and i don't know whats wrong, it had a good charge and i don't know what to do please help me.

    Try here:
    iOS: Not responding or does not turn on

  • HT201263 Okay so i was updating someone picture in my contacts it kept loading for a long time so i held the home button and the power button it slowly went black like it faded out and went black i tried everything i dont even know what wrong pleaase help

    Okay so i was updating someone picture in my contacts it kept loading for a long time so i held the home button and the power button it slowly went black like it faded out and went black i tried everything i dont even know what wrong i been had a crack on my phone and like i can see thats its light so like what do i do cause i tried plugging it into the computer and stuff and the computer dosent even bring up the logo which means the computer dosent reconize that my iphone is plugged in i had this problem before except it went white pleaase help

    Hi supreme_babes,
    If the display on your iPhone is black or isn't responding, you may find the following article helpful:
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/ts3281
    Regards,
    - Brenden

  • I backup up my iphone but didnt include password, and now want to restore new handset from backup and keep asking for password but has no idea what it is, pls help

    Hi all, i backup up iphone in itunes but not realised it was password protected and now want to restore new handset from backup but keep asking me for password but no idea what it was,, pls help...

    You are someone had to put a check in the box to encrypt your iPhone backup.
    Warning: If you encrypt an iPhone backup in iTunes and then forget your password, you will not be able to restore from backup and your data will be unrecoverable. If you forget the password you can continue to do backups and use the device, however you will not be able to restore the encrypted backup to any device without the password. You do not need to enter the password for your backup each time you back up or sync.
    If you cannot remember the password and want to start again, you will have to do a full software restore and when prompted by iTunes to select the backup to restore from, choose Set up as a new device.

  • TS1702 i if use "search" in music on my ipod touch 5th gen the result just show only album and playlist but nothing song result.whats wrong with it?please help

    i if use "search" in music on my ipod touch 5th gen the result just show only album and playlist but nothing song result.whats wrong with it?please help

    The users guide says:
    Spotlight searches the following:
    Contacts—All content
    Apps—Titles
    Music—Names of songs, artists, and albums, and the titles of podcasts and videos
    Podcasts—Titles
    Videos—Titles
    Audiobooks—Titles
    Notes—Text of notes
    Calendar (Events)—Event titles, invitees, locations, and notes
    Mail—To, From, and Subject fields of all accounts (the text of messages isn’t searched)
    Reminders—Titles
    Messages—Names and text of messages
    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Unsynce all music and resync
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup
    - Restore to factory settings/new iOS device.
    - Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • HELP PLEASE - WHATS WRONG WITH THIS CODE

    Hi. I get this message coming up when I try to compile the code,
    run:
    java.lang.NullPointerException
    at sumcalculator.SumNumbers.<init>(SumNumbers.java:34)
    at sumcalculator.SumNumbers.main(SumNumbers.java:93)
    Exception in thread "main"
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)
    I am not sure whats wrong with the code. Any assistance would be nice. The code is below.
    package sumcalculator;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SumNumbers extends JFrame implements FocusListener {
    JTextField value1;
    JTextField value2;
    JLabel equals;
    JTextField sum;
    JButton add;
    JButton minus;
    JButton divide;
    JButton multiply;
    JLabel operation;
    public SumNumbers() {
    SumNumbersLayout customLayout = new SumNumbersLayout();
    getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
    getContentPane().setLayout(customLayout);
    value1.addFocusListener(this);
    value2.addFocusListener(this);
    sum.setEditable(true);
    value1 = new JTextField("");
    getContentPane().add(value1);
    value2 = new JTextField("");
    getContentPane().add(value2);
    equals = new JLabel("label_1");
    getContentPane().add(equals);
    sum = new JTextField("");
    getContentPane().add(sum);
    add = new JButton("+");
    getContentPane().add(add);
    minus = new JButton("-");
    getContentPane().add(minus);
    divide = new JButton("/");
    getContentPane().add(divide);
    multiply = new JButton("*");
    getContentPane().add(multiply);
    operation = new JLabel();
    getContentPane().add(operation);
    setSize(getPreferredSize());
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    public void focusGained(FocusEvent event){
    try {
    float total = Float.parseFloat(value1.getText()) +
    Float.parseFloat(value2.getText());
    sum.setText("" + total);
    } catch (NumberFormatException nfe) {
    value1.setText("0");
    value2.setText("0");
    sum.setText("0");
    public void focusLost(FocusEvent event){
    focusGained(event);
    public static void main(String args[]) {
    SumNumbers window = new SumNumbers();
    window.setTitle("SumNumbers");
    window.pack();
    window.show();
    class SumNumbersLayout implements LayoutManager {
    public SumNumbersLayout() {
    public void addLayoutComponent(String name, Component comp) {
    public void removeLayoutComponent(Component comp) {
    public Dimension preferredLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    Insets insets = parent.getInsets();
    dim.width = 711 + insets.left + insets.right;
    dim.height = 240 + insets.top + insets.bottom;
    return dim;
    public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    return dim;
    public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    Component c;
    c = parent.getComponent(0);
    if (c.isVisible()) {c.setBounds(insets.left+24,insets.top+48,128,40);}
    c = parent.getComponent(1);
    if (c.isVisible()) {c.setBounds(insets.left+256,insets.top+48,128,40);}
    c = parent.getComponent(2);
    if (c.isVisible()) {c.setBounds(insets.left+408,insets.top+48,56,40);}
    c = parent.getComponent(3);
    if (c.isVisible()) {c.setBounds(insets.left+488,insets.top+48,152,40);}
    c = parent.getComponent(4);
    if (c.isVisible()) {c.setBounds(insets.left+128,insets.top+136,72,40);}
    c = parent.getComponent(5);
    if (c.isVisible()) {c.setBounds(insets.left+248,insets.top+136,72,40);}
    c = parent.getComponent(6);
    if (c.isVisible()) {c.setBounds(insets.left+368,insets.top+136,72,40);}
    c = parent.getComponent(7);
    if (c.isVisible()) {c.setBounds(insets.left+488,insets.top+136,72,40);}
    c = parent.getComponent(8);
    if (c.isVisible()) {c.setBounds(insets.left+176,insets.top+48,56,40);}
    }

    Thank you. How do i amend this? I have defined value1though.Yes, you did - but after the call to addFocusListener(...). It needs to be before it.
    BTW, you did the same thing with "value2.addFocusListener(this)" and "sum.setEditable(true)" on the next two lines. You're attempting to call a method on an object that doesn't exist yet (i.e., you haven't called new yet).

Maybe you are looking for

  • Having trouble with JCheckBox and JTree

    I am trying to render the JTree to display JCheckBox's instead of just ordinary JLabels. It's fine, compiles, and when you view it it looks normal, until you try to check one. You can't check it at all. What am i doing wrong with this? Thanks

  • How to fill out and submit a web form using LabVIEW

    Almighty Forum, This question will require knowledge not only of LabVIEW, but also of HTML, JavaScripting, and possibly more.  I don't know about you, but I have an on-line account for pretty much everything: Bank, Credit Card, Savings, ETrade, 401K,

  • Hard Drive, Printer and AEBS

    I have a Canon Pixma printer hooked up to USB port on AEBS which I just bought. Everything works without problems (so far at least). This may seem like a stupid question, but I'd like to also hook up one of my LaCie external hard drives to access wir

  • Excel Add-in & Multiple excel sessions.

    We all know the limitation of the add-in with multiple sessions of excel going (unpredictable results), but for an accountant it seems pretty restrictive. Especailly if there are long running retrieves. e.g. a macro that retrieves data for multiple s

  • Help with transferring contact list

    So here's my problem, I had a Pearl 8130, and broke the trackball on it so it is no longer functional.  I just received my Curve in the mail today, and I want to move all my contacts from my Pearl to my Curve.  Everytime I plugged my phone into my co