4

I am trying to print malayalam words fetched from rssfeeds provided by various medias like "Matrubhumi" "Indiavision" to a jtext area.

What I am doing is saving all the topics from rssfeed to a text file and then reading them line by line to print it into a textarea. But at some words I am getting ArrayIndexOutofBoundException.

For example printing "ബോസ്റ്റണ്‍ സംഭവം: അമേരിക്കയിലെ സിഖ് സമൂഹം ആശങ്കയില്‍ " gives the error. Please point out any mistakes I am making. Also I have changed font to "Meera" so I do not think it is the problem. Also strings like " ബംഗാളില്‍ ചിട്ടി കമ്പനി പൊളിഞ്ഞു, സംഘര്‍ഷം " do not show any error and opens the application window. Thanks in advance.

  BufferedReader demo = new BufferedReader(new FileReader(Name));
  jScrollPane1 = new javax.swing.JScrollPane();
  jTextArea1 = new javax.swing.JTextArea();
  setBackground(java.awt.Color.white);
  setPreferredSize(new java.awt.Dimension(1366, 768));
  jTextArea1.setColumns(30);
  jTextArea1.setRows(10);
  jTextArea1.setBorder(null);
  jTextArea1.setFont(new java.awt.Font("Meera", 1, 24));
  jTextArea1.setEditable(false);
  jScrollPane1.setViewportView(jTextArea1);
  jTextArea1.setWrapStyleWord(true);
  jTextArea1.setLineWrap(true);
    while ((sCurrentLine = demo.readLine()) != null){
    jTextArea1.append(sCurrentLine);
}
  private javax.swing.JTextArea jTextArea1;
  public static final java.lang.Character.UnicodeBlock MALAYALAM = null;

The rest of the code is auto generated code from netbeans. This is the second class. The main class deals with fetching rssfeed and saving the topics into a text file. And the name of the text file is passed to this class where FileReader() is used to gain access to the file and fetch the contents line by line to a string variable "sCurrentLine". And using jTextArea.append() append the text into the text area.

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 432
at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:772)
at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
at sun.font.ExtendedTextSourceLabel.getLineBreakIndex(ExtendedTextSourceLabel.java:455)
at java.awt.font.TextMeasurer.calcLineBreak(TextMeasurer.java:325)
at java.awt.font.TextMeasurer.getLineBreakIndex(TextMeasurer.java:561)
at java.awt.font.LineBreakMeasurer.nextOffset(LineBreakMeasurer.java:358)
at java.awt.font.LineBreakMeasurer.nextLayout(LineBreakMeasurer.java:440)
at javax.swing.text.TextLayoutStrategy.sync(TextLayoutStrategy.java:323)
at javax.swing.text.TextLayoutStrategy.insertUpdate(TextLayoutStrategy.java:70)
at javax.swing.text.FlowView.loadChildren(FlowView.java:143)
at javax.swing.text.CompositeView.setParent(CompositeView.java:139)
at javax.swing.text.FlowView.setParent(FlowView.java:289)
at javax.swing.plaf.basic.BasicTextAreaUI$PlainParagraph.setParent(BasicTextAreaUI.java:239)
at javax.swing.text.CompositeView.replace(CompositeView.java:217)
at javax.swing.text.BoxView.replace(BoxView.java:181)
at javax.swing.text.View.updateChildren(View.java:1116)
at javax.swing.text.View.insertUpdate(View.java:700)
at javax.swing.plaf.basic.BasicTextUI$RootView.insertUpdate(BasicTextUI.java:1602)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.insertUpdate(BasicTextUI.java:1861)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:202)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:749)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:708)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
at javax.swing.JTextArea.append(JTextArea.java:477)

Also I tried to run the program by enclosing the error generatingportion in a try catch, but then i got another ArrayIndexOutofBoundException but this time at a diffrent line.Code Segment

 String RSSName;
 RSSName = "Matrubhumi";
 ReadTest demo = new ReadTest();
 demo.NewsFeed(RSSName); //Creates text file and fetch data from rssfeed
 JFrame frame = new JFrame();
 frame.setLayout(new BorderLayout());
 frame.add(new ImportantNews(RSSName),BorderLayout.CENTER);
 frame.setSize(1366, 768);
 frame.setVisible(true); // new exception is thrown in this line
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 



 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 496
at sun.font.ExtendedTextSourceLabel.createCharinfo(ExtendedTextSourceLabel.java:772)
at sun.font.ExtendedTextSourceLabel.getCharinfo(ExtendedTextSourceLabel.java:509)
at sun.font.ExtendedTextSourceLabel.getCharX(ExtendedTextSourceLabel.java:353)
at java.awt.font.TextLine$3.computeFunction(TextLine.java:515)
at java.awt.font.TextLine.applyFunctionAtIndex(TextLine.java:651)
at java.awt.font.TextLine.getCharXPosition(TextLine.java:668)
at java.awt.font.TextLine.getCharLinePosition(TextLine.java:678)
at java.awt.font.TextLayout.buildCache(TextLayout.java:683)
at java.awt.font.TextLayout.ensureCache(TextLayout.java:655)
at java.awt.font.TextLayout.getAdvance(TextLayout.java:885)
at sun.font.FontDesignMetrics.charsWidth(FontDesignMetrics.java:510)
at javax.swing.text.Utilities.getTabbedTextWidth(Utilities.java:279)
at javax.swing.text.GlyphPainter1.getSpan(GlyphPainter1.java:62)
at javax.swing.text.GlyphView.getPreferredSpan(GlyphView.java:592)
at javax.swing.text.View.getMaximumSpan(View.java:269)
at javax.swing.text.ParagraphView.findEdgeSpan(ParagraphView.java:768)
at javax.swing.text.ParagraphView.calculateMinorAxisRequirements(ParagraphView.java:736)
at javax.swing.plaf.basic.BasicTextAreaUI$PlainParagraph.calculateMinorAxisRequirements(BasicTextAreaUI.java:272)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:568)
at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:903)
at javax.swing.text.BoxView.checkRequests(BoxView.java:935)
at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:343)
at javax.swing.text.BoxView.layout(BoxView.java:708)
at javax.swing.text.BoxView.setSize(BoxView.java:397)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1714)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:917)
at javax.swing.plaf.basic.BasicTextAreaUI.getPreferredSize(BasicTextAreaUI.java:120)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1651)
at javax.swing.JTextArea.getPreferredSize(JTextArea.java:619)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:790)
at java.awt.Container.layout(Container.java:1503)
at java.awt.Container.doLayout(Container.java:1492)
at java.awt.Container.validateTree(Container.java:1688)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validateTree(Container.java:1697)
at java.awt.Container.validate(Container.java:1623)
at java.awt.Container.validateUnconditionally(Container.java:1660)
at java.awt.Window.show(Window.java:1033)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1014)
SaintLike
  • 9,119
  • 11
  • 39
  • 69

1 Answers1

0

This may be an encoding issue as described in this thread

Try replacing this line

BufferedReader demo = new BufferedReader(new FileReader(Name));

with

new BufferedReader(new InputStreamReader(new FileInputStream(filePath), encoding));

where encoding should be the encoding used in the file you're storing your topics in.

Community
  • 1
  • 1
Zoltán
  • 21,321
  • 14
  • 93
  • 134
  • Thanks for that fast reply. But I still got the same error when I ran the program after doing the changes u said... – Arun Chidanandan Apr 21 '13 at 00:14
  • 2
    There seems to be a bug report about this: http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=8b833c54cb93d6c9cf416667dc02?bug_id=6374477 – Zoltán Apr 21 '13 at 00:24