Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:46:23+00:00 2026-06-14T13:46:23+00:00

Here is a code snippet. Its giving arrayindexoutofboundexception. dont know why ? import java.io.File;

  • 0

Here is a code snippet. Its giving arrayindexoutofboundexception. dont know why ?

import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;


public class wordcount 
{
public static void main(String[] args) throws Exception
{


        File file = new File("E:\\myFiles\\abc.doc");
        FileInputStream fis=new FileInputStream(file.getAbsolutePath());
        HWPFDocument document=new HWPFDocument(fis);
        WordExtractor extractor = new WordExtractor(document);
        String [] fileData = extractor.getParagraphText();

        for (int i = 0; i < fileData.length; i++)
            {  

               // System.out.println(fileData[i].toString());
                String[] paraword = fileData[i].toString().split(" ");
               // out.println(paraword.length);

                if(paraword[i].length() == 0 )
                {
                    System.out.println("\n");
                }
                else if(paraword[i].length() > 0 && paraword[i].length() < 12)
                {
                    for(int k=0 ; k < paraword[i].length()-1 ; k++)
                    {
                       System.out.println(paraword[k].toString());
                    }
                }
                else if(paraword[i].length() >= 12  )
                {
                    for(int k=0 ; k < 12 ; k++)
                    {
                       System.out.println(paraword[k].toString());
                    }
                }


               System.out.println("\n");

            }

}
}

This is the image of the abc.doc file

this is the abc.doc

Note : Expected output will be printed on java console.

and the output will contain 12 words in each line. But after executing first line the error occurs.

Any help would be appreciated

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:46:24+00:00Added an answer on June 14, 2026 at 1:46 pm

    Honestly, I’m not familiar with the apache.org API, but just by looking at your logic it looks like you want to replace every instance of:

    paraword[i].length()

    with:

    paraword.length
    

    Because it looks like you want to check how many words are in the paragraph and not how long the first word of the paragraph is. Correct me if I’m wrong, but I think that will fix you up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't know why I'm facing that error ! Here is my code snippet
I'm reading a csv file using c# here is a little code snippet. using
Here is a code snippet from DirectShowNet library, used to open a video file:
Here's a code snippet I'm trying to get to work, but its loop won't
Here is my code snippet: int a; if(a=8) cout<<Its right; else cout<<Not at all;
Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Here is my code snippet where I'am taking confidence with initialization blocks class Father{
I have a class with two constructors (C#). Here is the code snippet: public
Here is the following code-snippet I'm using in my Google Spreadsheet onEdit() function: else
here is the relevent code snippet: public static Rand searchCount (int[] x) { int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.