我正在尝试将从“Matrubhumi”“Indiavision”等各种媒体提供的 rssfeed 中提取的马拉雅拉姆语单词打印到 jtext 区域。
我正在做的是将所有主题从 rssfeed 保存到文本文件中,然后逐行读取它们以将其打印到 textarea 中。但有些话我得到了ArrayIndexOutofBoundException
。
例如打印“ബോസ്റ്റൺ സംഭവം: അമേരിക്കയിലെ സിഖ് സമൂഹം ആശങൽക”给出错误。请指出我犯的任何错误。此外,我已将字体更改为“Meera”,所以我认为这不是问题。像“ ബംഗാളിൽ ചിട്ടി കമ്പനി പൊളിഞ്ഞു, സംഘർഷം ”等字符串不会显示任何错误并打开应用程序窗口。提前致谢。
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;
其余代码是从 netbeans 自动生成的代码。这是第二课。主类处理获取 rssfeed 并将主题保存到文本文件中。文本文件的名称被传递给这个类,该类FileReader()
用于访问文件并将内容逐行获取到字符串变量“sCurrentLine”。并使用jTextArea.append()
将文本附加到文本区域。
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)
此外,我尝试通过将错误生成部分包含在 try catch 中来运行程序,但后来我得到了另一个ArrayIndexOutofBoundException
,但这次是在不同的行。代码段
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)