Having trouble with counting program

I made a program to count the number of lines and number of characters from an input file. My program (below) successfully does that, as far as I know. I must also call a function to count the number of occurences of a certain letter, in this case 'a'. I can compile with no errors, but when I execute, it says there is a problem at line 1961, which is the next to last character in my input file. It says it's out of bounds....??? Thanks for the help.
import java.util.*;
public class Count{
     public static void main(String[] args){
          Scanner keyBoard = new Scanner(System.in);
          String line;
          String totallines = "";
          int countline = 0;
          int countchar = 0;
          int totalcharacters = 0;
          int totallength = 0;
          while(keyBoard.hasNext()){
               line = keyBoard.nextLine();
               String lower = line.toLowerCase();
               countline++;
               int len = line.length();
               totallength = totallength + len;
               totalcharacters = totalcharacters + countchar;
               totallines = totallines + line;          
          totallength = totallength + 1;
          System.out.println(countline);
          System.out.println(totallength);
          countChar('a', totallines, totallength);
     public static int countChar(char ch, String s, int totallength){
          int countcharacter = 0;
          for (int k = totallength-1; k >= 0; k--){
               if (s.charAt(k) == ch){
                    countcharacter++;
          System.out.println(countcharacter);
          return countcharacter;
}

--...OutOfBounds exception means to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.
--it also applies if you're goin to accessed your String.. try to double check all your loops that has an access to your strings....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • I need to un-install then re-install my Adobe Creative Suite 6. I am having troubles with the programs.

    I need to un-install then re-install my Adobe Creative Suite 6. I am having troubles with the programs.

    Hi legates1,
    You can uninstall the software by going to Control Panel > Programs
    You can also use the Creative Suite Cleaner tool ( Use the CC Cleaner Tool to solve installation problems | CC, CS3-CS6 ) to remove the software completely.
    Regards,
    Rave

  • Having trouble with throws...

    Hey there.
    I'm fairly new to java so bear with me here.
    I'm having trouble with a program that, in short, reads from a file.
    Let me shorten a show the code to you...
    //main opens up and in a bit we get to...
    if (loginVerify())
    //and the if continues.
    fileIn.close();
    //main ends
    public boolean loginVerify() throws IOException
         openIn(); //Checks for validity - It's a long story why I //didn't just put the code in loginVerify(). I //don't think it should matter.
    String str = verifyLog(); //Does the actual reading
         str = str.substring(1);
         if (str == placeHold) //Don't worry about not making placeHold,
    //I made it global for testing reasons.
              return true;
         else
              return false;
    private String verifyLog() throws IOException
         String str;
         while (true)
              str = fileIn.readLine();
              if (str == null)
                   break;
              else if (str.charAt(0) == 1)
                   return str;
              //ADDITION OF OTHER NUMBERS
              else
                   return str = "invalid";
    private void readIn() throws IOException
         BufferedReader console =
    new BufferedReader(new InputStreamReader(System.in));
    openInputFile(fileName);
    if (fileIn == null)
    System.out.println("*** Can't open " + fileName + " ***");
    return;
    private static void openInputFile(String fileName)
    try
    fileIn = new BufferedReader(new FileReader(fileName));
    catch (FileNotFoundException e)
    So it's fairly simple. It checks for validity and then reads lines until it finds one with the first char as '1' when it finds it, it reads the rest of the line off.
    The error I'm getting is as follows: Exception java.io.IOException must be caught, or it must be declared in the throws clause of this method.
    I've added throws IOException to them in attempts to fix the error but to no avail. I've tryed putting the catch in different spots... again, doesn't work.
    I'm using codewarrior IDE version 5. I'm fairly sure it's the newest. I installed Java SDK 1.3 with codewarrior originally but I installed 1.4.1 recently.
    If you need to see anything else about it, please tell me. I'd be more than happy to post a little more if it'll help.
    Thanks

    Ok. I worked through a bunch of throws and now I've found one I can't seem to conquer.
    private String verifyLog()
           String str = "";
           while (true)
                try {
                str = fileIn.readLine();
                catch (FileNotFoundException g) {
                if (str == null)
                     break;
                else if (str.charAt(0) == 1)
                     return str;
                //ADDITION OF OTHER PEOPLE
                else
                     return str = "invalid";
           return str = "invalid";
      }This time the error is at the reference to readLine() and it tells me the same error as before. I have a catch set up there, don't I?
    readLine() is something I didn't create so I don't know how I'd tell it to throw an exception if I had to...
    Thanks

  • Having trouble downloading my program

    I own an Adobe Acrobat X Pro in my account (purchased in Dec 2011).  I'm having trouble with the program on my computer and would like to download again and reinstall.  The download link on my account purchase record gives me an error "#413 - Header length too large".  Shouldn't I be able to download my program at any time?

    Lisley58 please clear your cache and cookies and try again with your current web browser.  If the problem continues then please utilize a different web browser.

  • I'm having trouble with My adobe Creative Suite 4 Design Standard programs opening. They will bounce to open but won't open up and eventually I will need to force quit as they aren't responding.  I'm thinking it may be a font issue but need some support A

    I'm having trouble with My adobe Creative Suite 4 Design Standard programs opening. They will bounce to open but won't open up and eventually I will need to force quit as they aren't responding.  I'm thinking it may be a font issue but need some support ASAP!

    Nobody can tell you anything without proper system info or other technical details like the crash logs.
    Mylenium

  • I'm having trouble with something that redirects Google search results when I use Firefox on my PC. It's called the 'going on earth' virus. Do you have a fix that could rectify the vulnerability in your software?

    I'm having trouble with a virus or something which affects Google search results when I use Firefox on my PC ...
    When I search a topic gives me pages of links as normal, but when I click on a link, the page is hijacked to a site called 'www.goingonearth.com' ...
    I've done a separate search and found that other users are affected, but there doesn't seem to be a clear-cut solution ... (Norton, McAfee and Kaspersky don't seem to be able to detect/fix it).
    I'd like to continue using the Firefox/Google combination (nb: the hijack virus also affects IE but not Safari) - do you have a patch/fix that could rectify the vulnerability in your software?
    thanks

    ''' "... vulnerability in your software?" ''' <br />
    And it affects IE, too? Ya probably picked up some malware and you blame it on Firefox.
    Install, update, and run these programs in this order. They are listed in order of efficacy.<br />'''''(Not all programs detect the same Malware, so you may need to run them all to solve your problem.)''''' <br />These programs are all free for personal use, but some have limited functionality in the "free mode" - but those are features you really don't need to find and remove the problem that you have.<br />
    ''Note: If your Malware infection is bad enough and you are mis-directed to URL's other than what is posted, you may have to use a different PC to download these programs and use a USB stick to transfer them to the afflicted PC.''
    Malwarebytes' Anti-Malware - [http://www.malwarebytes.org/mbam.php] <br />
    SuperAntispyware - [http://www.superantispyware.com/] <br />
    AdAware - [http://www.lavasoftusa.com/software/adaware/] <br />
    Spybot Search & Destroy - [http://www.safer-networking.org/en/index.html] <br />
    Windows Defender: Home Page - [http://www.microsoft.com/windows/products/winfamily/defender/default.mspx]<br />
    Also, if you have a search engine re-direct problem, see this:<br />
    http://deletemalware.blogspot.com/2010/02/remove-google-redirect-virus.html
    If these don't find it or can't clear it, post in one of these forums for specialized malware removal help: <br />
    [http://www.spywarewarrior.com/index.php] <br />
    [http://forum.aumha.org/] <br />
    [http://www.spywareinfoforum.com/] <br />
    [http://bleepingcomputer.com]

  • Having Trouble With E-mails That Involve Animation

    This is too weird. When I receive an e-mail that has animation in it it comes through freeze framed in Mail. It does not matter if it is in my .Mac account or Verizon account. Just for the heck of it I forwarded it to myself using the Verizon account and opened it in Safari. I also did the same thing with my .mac account. I opened it on the web. Bingo, I had animation. I am also having trouble with WMV's. Why can I not get any animation in Mail? Is there something I am doing wrong? any way to correct this?

    OK, from the sound of your post, you have a limited knowledge about email. Let me see if I can help. I would guess that you have a Windows machine that you have used in the past. Your email address must be a "pop" address. That means that your internet service provider has a server where your mail is sent. This is different than a web mail address, that is accessed remotely with a web browser, such as Internet Explorer, Firefox, or Safari. You must then be using an email program, such as Outlook Express, to go get the email onto your local machine. Any email program can do this. Open up the accounts tab in Outlook Express, and write down the settings. There will be one for the incoming server, and one for the outgoing server. Now, on your Mac, you can use the email program provided, such as Mac Mail, and put the settings in there. You can now send and receive to your Mac using your supplied email address. You can use another program such as Thunderbird to do this if you want. You don't have to use Mac Mail.
    Getting your old email off of the Windows computer is a bit harder, so hopefully you don't need to do that. But if you do, I can direct you on how to do that also.

  • I am having trouble with a form, won't tab to 2nd page...

    I am having trouble with a form I created in Acrobat Pro 10. I created tabs etc, they all work wonderfully in Adobe, but once I uploaded it onto the web-based program for other users, the tabs only work  on page 1, I have to click on page 2 to keep tabbing through.  It won't tab into it.  Any advise?  Also, when the users open it it opens in the web.

    1. The library is separate from the application, so re-installing shouldn't cause an issue with the actual photos. But it would be foolhardy in the extreme to do anything without first backing up.
    2. Often these issues are caused by a damaged Library, so reinstalling doesn't change much.
    FWIW
    To re-install iPhoto
    1. Put the iPhoto.app in the trash (Drag it from your Applications Folder to the trash)
    2a: On 10.5:  Go to HD/Library/Receipts and remove any pkg file there with iPhoto in the name.
    2b: On 10.6: Those receipts may be found as follows:  In the Finder use the Go menu and select Go To Folder. In the resulting window type
    /var/db/receipts/
    A Finder Window will open at that location and you can remove the iPhoto pkg files.
    3. Re-install.
    If you purchased an iLife Disk, then iPhoto is on it.
    If iPhoto was installed on your Mac when you go it then it’s on the System Restore disks that came with your Mac. Insert the first one and opt to ‘Install Bundled Applications Only.
    If you purchased it on the App Store you can find it in your Purchases List.
    Alternative approach:
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • I'm having trouble with installing a 8g kit in my late 2009 mac mini. when the parts are installed all i get is a beeping sound, is there any way to get around this?

    i'm having trouble with installing a 8g kit in my late 2009 mac mini. when the parts are installed all i get is a beeping sound, is there any way to get around this?

    What is the source & link to this 8 GB kit please?
    Can you count the beeps or flashes?
    1 beep = no RAM installed
    2 beeps = incompatible RAM types
    3 beeps = no good banks
    4 beeps = no good boot images in the boot ROM (and/or bad sys config block)
    5 beeps = processor is not usable
    In addition to the beeps, on some computers the power LED will flash a corresponding number of times plus one. The LED will repeat the sequence after approximately a 5-second pause. The tones are only played once.
    Note: In this case, a flash is considered to be 1/4 second or 250 ms or greater in length.
    http://support.apple.com/kb/HT1547

  • I'm having trouble with a multi channel acquisition and download with PXI-5922

    I am having trouble with getting data out from both channels of a PXI-5922.  My software seems to be working, but when I do the fetch there is no data for the second channel.  I am using the same format for all of the channelList inputs (0,1).  I've checked the instrument handles and anything else I can think of, but this is my first time trying to collect data on 2 channels of a digitizer.  Any help would be appreciated.

    Hi schliepe,
    Try checking your code against an existing example. The
    Developer Zone Example: Independent
    Channel Configuration with NI-SCOPE is a good VI to reference. Also note
    that there are several examples that come with the NI-SCOPE driver. They can be
    found in Windows by going to Start »
    Programs » National Instruments » NI SCOPE » Examples. Additionally, if you find that the examples are not working either, verify that both channels are functioning by running the
    NI-SCOPE Soft Front Panel.
    Please post back if you have any questions. Have a great
    day!
    Ryan D.
    District Sales Manager for Boston & Northern New England
    National Instruments

  • Having trouble with Microsoft Outlook

    Aloha:
    I am having trouble with my Microsoft Outlook e-mail program.  I can send and receive e-mails OK, but it is constantly trying to send an email message that is not formed correctly.  My error panel remains full of the errors.
    I erased all the error messages, but it just continues to add them.
    I am not, presently, even trying to send an email.  However, in no time at all this widow will be full of such error messages.
    What might my problem be?
    Thanks
    Dan Page
    Hawaii

    Post in the Microsoft for Mac Support forums.

  • Having trouble with my signed applet(if it's properly signed that is)

    hi
    I'm having trouble with my supposedly signed applet. I'm trying to execute a specific program in this case trilian from my browser. i'm using firefox
    first my java code
    package applet;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class RunApplet extends JApplet {
        JButton jButton = new JButton();
        FlowLayout flowLayout1 = new FlowLayout();
        public RunApplet() {
            try {
                init();
            } catch (Exception ex) {
                ex.printStackTrace();
        private void init() throws Exception {
            try {
                this.getContentPane().setLayout(flowLayout1);
                this.setSize(new Dimension(100, 200));
                jButton.setText("Trillian");
                jButton.addActionListener(new RunApplet_jButton_actionAdapter(this,
                        "\"C:\\Program Files\\Trillian\\trillian.exe\""));
                this.getContentPane().add(jButton, null);
            } catch (Exception e) {
                e.printStackTrace();
    class RunApplet_jButton_actionAdapter implements ActionListener {
        private RunApplet adaptee;
        private String programPath;
        RunApplet_jButton_actionAdapter(RunApplet adaptee, String programPath) {
            this.adaptee = adaptee;
            this.programPath = programPath;
        public void actionPerformed(ActionEvent e) {
            try {
                Runtime.getRuntime().exec(this.programPath);
            } catch (IOException ex) {
    }And my applet code
    <html>
    <body>
    <!--"CONVERTED_APPLET"-->
    <!-- HTML CONVERTER -->
    <object
        classid = "clsid:CAFEEFAC-0015-0000-0005-ABCDEFFEDCBA"
        codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5_0_05-windows-i586.cab#Version=5,0,50,5"
        >
        <PARAM NAME = CODE VALUE = "applet.RunApplet.class" >
        <PARAM NAME = ARCHIVE VALUE = "myfile.jar" >
        <param name = "type" value = "application/x-java-applet;jpi-version=1.5.0_05">
        <param name = "scriptable" value = "false">
        <comment>
         <embed
                type = "application/x-java-applet;jpi-version=1.5.0_05" \
                CODE = "applet.RunApplet.class" \
                ARCHIVE = "myfile.jar"
             scriptable = false
             pluginspage = "http://java.sun.com/products/plugin/index.html#download">
             <noembed>
                </noembed>
         </embed>
        </comment>
    </object>
    <!--
    <applet CODE = "applet.RunApplet.class" ARCHIVE = "myfile.jar">
    </applet>
    -->
    <!--"END_CONVERTED_APPLET"-->
    </body>
    </html>Creating my key:
    keytool -genkey -alias sitekey -keystore "C:\Program Files\Java\jdk1.5.0_05\jre\lib\security\cacerts"Now the process of creating the jar file and signing it:
    1. jar cf myfile.jar *.class
    2. jarsigner -keystore "C:\Program Files\Java\
    jdk1.5.0_05\jre\lib\security\cacerts" myfile.jar sitekeyNow this is the way i've been using then and the first time i get the "do you want to trust" screen but still i get a security exception.
    Exception in thread "AWT-EventQueue-10" java.security.AccessControlException: access denied (java.io.FilePermission <<ALL FILES>> execute)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkExec(Unknown Source)
         at java.lang.ProcessBuilder.start(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at java.lang.Runtime.exec(Unknown Source)
         at applet.RunApplet_jButton_actionAdapter.actionPerformed(RunApplet.java:73)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
         at java.awt.Component.processMouseEvent(Unknown Source)
         at javax.swing.JComponent.processMouseEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
         at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)Is there anybody who have an idea what can be wrong?
    regards
    thallish

    ok i solved i myself. i assigned a different and thereby correct keystore and now it works like it should
    regards
    thallish

  • Having trouble with e-mail

    I recently bought a macbook for college, and I am having trouble with my e-mail. I have an account on outlook express that works well, and i just wanted to know if there is any way that I could access it from this laptop.
    I am going to college and they send me important stuff, so I need that address. If it is not possible then what kind of e-mail address should i make (yahoo, etc.)

    OK, from the sound of your post, you have a limited knowledge about email. Let me see if I can help. I would guess that you have a Windows machine that you have used in the past. Your email address must be a "pop" address. That means that your internet service provider has a server where your mail is sent. This is different than a web mail address, that is accessed remotely with a web browser, such as Internet Explorer, Firefox, or Safari. You must then be using an email program, such as Outlook Express, to go get the email onto your local machine. Any email program can do this. Open up the accounts tab in Outlook Express, and write down the settings. There will be one for the incoming server, and one for the outgoing server. Now, on your Mac, you can use the email program provided, such as Mac Mail, and put the settings in there. You can now send and receive to your Mac using your supplied email address. You can use another program such as Thunderbird to do this if you want. You don't have to use Mac Mail.
    Getting your old email off of the Windows computer is a bit harder, so hopefully you don't need to do that. But if you do, I can direct you on how to do that also.

  • I have 64-bit Vista on an HP laptop, and am having trouble with P4

    I have 64-bit Vista on an HP laptop, and am having trouble with P4. When I go to the "Compatibility" tab in for the P4 .exe file, 32-bit Vista does not show up as a compatibility option. The latest version shown is XP with SP2. Am I missing something? Is there a patch or download that updates P4?(The problem I'm having is stuttering and stopping in the imported avi2 files I have downloaded from my Panasonic digital camcorder and converted from avi to avi2 using DVDate. Also, I get stuttering with digital photos - jpg files - that I want to insert in the movie with added narration.)

    A.T. Romano
    It gets a little complicated. This is a simplification, but I hope this
    helps to visualize what's happening.
    The 32 bit and 64 bit environments are separated from each other.
    There are separate program files directories, separate shared dll library
    directories, and even separate registry entries. You can't mix 32 and
    64 bit modules, and some applications, like Internet Explorer, install
    both a 32 bit and a 64 bit version on the same computer. (IE does that
    so it can process web pages that use 32 bit executable controls).
    Vista 64 has 32 bit emulation built-in using a subsystem called Windows
    on Windows 64 or WOW64 for short. WOW64 intercepts 32 bit
    application calls to the operating system and handles the 32 to 64 bit
    conversions and the redirection of the file and registry locations.
    The program files themselves contain flags that indicate whether they
    are 32 bit and whether the file uses the 64 bit version of the file
    structure.
    If the program is marked 32 bit, it will run in 32 bit using WOW64.
    Programs are generally installed by an installer program which places
    the application files in the proper locations and writes the registry
    entries and any other setup tasks that are needed. To install a 64
    bit program, a 64 bit installer is needed. For 32 bit installers, the files
    and registry entries are redirected to the 32 bit locations.

  • I am having trouble with the preview of songs on itunes it will not play the 1:30 preview

    I am having trouble with the preview of songs,I am not getting the full 1:30 preview of the music

    Close your iTunes,
    Go to command Prompt -
    (Win 7/Vista) - START/ALL PROGRAMS/ACCESSORIES, right mouse click "Command Prompt", choose "Run as Administrator".
    (Win XP SP2 n above) - START/ALL PROGRAMS/ACCESSORIES/Command Prompt
    In the "Command Prompt" screen, type in
    ipconfig /flushdns
    Hit "ENTER" key
    Restart your computer.
    Now try your preview music again.

Maybe you are looking for