【问题标题】:LWUIT HtmlComponent out of memory exceptionLWUIT HtmlComponent 内存不足异常
【发布时间】:2012-08-28 07:17:09
【问题描述】:

我想在 LWUIT 表单屏幕上显示来自 Rss 文件的图像和描述 这是我的代码:

HTMLComponent com=new HTMLComponent();
com.setBodyText(detailNews.getDescription());
form2.addComponent(com);

代替 *detailNews.getDescription()*,在循环中形成一个Rss URL的字符串是

<p><img border="1" align="left" width="150" vspace="2" hspace="2" height="159" src="/tmdbuserfiles/Prithvi2_launch1(3).jpg" alt="Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State" />The Strategic Forces 
Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>

如果我执行,我将面临应用程序意外退出,因为它耗尽了内存异常

【问题讨论】:

    标签: java-me lwuit


    【解决方案1】:

    如果您不需要显示图像,请从 html 字符串中删除 img 标签。

    String description = detailNews.getDescription();
    StringBuffer newDescription = new StringBuffer();
    int imgIndex = description.indexOf("<img");
    
    newDescription.append(description.substring(0, imgIndex));
    imgIndex = description.indexOf(">", imgIndex + 1);
    newDescription.append(description.substring(imgIndex + 1));
    description = newDescription.toString();
    com.setBodyText(description);
    

    【讨论】:

    • 我正在读取 4 个 Rss 文件并在我的表单上显示选项卡,我能够读取 4 个文件并成功显示标题和图像(注意:图像使用 ListCellrenderer 显示),但是当我点击列表项,我需要显示描述,但我再次面临内存不足异常并且我的应用程序正在关闭?
    • 您可能创建了太多对象来处理点击事件。但我认为这是另一个问题......
    • 现在我再次测试,即使我也无法显示标题,在中间本身,它正在抛出内存不足异常
    • 你好,你能提供你的邮箱吗
    猜你喜欢
    • 1970-01-01
    • 2010-10-05
    • 1970-01-01
    相关资源
    最近更新 更多