gpt4 book ai didi

java - 在 jtext 区域中打印 unicode 字词时出现 ArrayIndexOutofBoundException。 (马拉雅拉姆语词)

转载 作者:行者123 更新时间:2023-11-29 09:03:40 24 4
gpt4 key购买 nike

我正在尝试将从“Matrubhumi”“Indiavision”等各种媒体提供的 rssfeeds 中获取的马拉雅拉姆语单词打印到 jtext 区域。

我正在做的是将所有主题从 rssfeed 保存到一个文本文件,然后逐行读取它们以将其打印到文本区域中。但有些话我得到了 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)

最佳答案

这可能是编码问题,如 this thread 中所述

尝试替换这一行

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

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

encoding 应该是您存储主题的文件中使用的编码。

关于java - 在 jtext 区域中打印 unicode 字词时出现 ArrayIndexOutofBoundException。 (马拉雅拉姆语词),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16125840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com