LWUIT Uncaught exception: java.lang.OutOfMemoryErr

2019-07-27 10:04发布

问题:

I developed an Rss Application using LWUIT Tabs,i want to display Rss Feed Titles and images on my Lwuit Tab screen,but when i run my application i am able to display three List (title with image)items Sucessfully,after that i am facing java.lang.OutOfMemoryError(stack trace incomplete) Eventhough there are list items present?can any one help......thanks...

Here my Code:

public class Process {
     protected XMLMidlet midlet;

     Form form1;
     Image image;
     Tabs tabs;
     private List myNewsList;
    private Vector topnews;
    private Vector topstory;
    private Command cmdExit;
    private Command m_backCommand;
      private List newsList;
        private Form form2;
    Process(XMLMidlet midlet) throws IOException {
           this.midlet=midlet;
           topnews = new Vector();
        topstory = new Vector();
       tabs = new Tabs();
        form1 = new Form();
        form2=new Form();
           try {
            newsList = new List(topnews);
            newsList.setScrollVisible(false);
            newsList.setRenderer(new NewsListCellRenderer());   
         m_backCommand = new Command("Back");
        cmdExit = new Command("EXIT");
           tabs.addTab("Topstory", newsList); 
            form1.addComponent(BorderLayout.CENTER, tabs);                           
}
catch(Exception e){
    e.printStackTrace();
}           }

   public void process() {
       try{
   String url = "http://www.teluguone.com/news/tonefeeds/news/news-1.rss";

       form1.show();
       ParseThread myThread = new ParseThread(this);
       myThread.getXMLFeed(url);

        } catch (Exception e) {

        }

    }
   public void addNews(News newsItem) {

try{
            topnews.addElement(newsItem);
            newsList.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent ae) {

                    List source = (List) ae.getSource();
                    News selectedNewsItem = (News) source.getSelectedItem();
                    if (selectedNewsItem != null) {
                        displayCompleteNewsScreen(selectedNewsItem);

                    }

                }


            });
}
catch(OutOfMemoryError r){

}
        form1.show();


    }


    private void displayCompleteNewsScreen(News detailNews) {

       try{ 
        form2.removeAll();
        form2.repaint();
        form2.addCommand(m_backCommand);
        form2.addCommandListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                form1.show();
            }
        });

        HTMLComponent com=new HTMLComponent();
        com.setPreferredSize(new Dimension(300,300));
com.setShowImages(false);

       com.setBodyText(detailNews.getDescription());
       form2.addComponent(com);
        //form2.addComponent(big);
        }
       catch(OutOfMemoryError e){

       }
        form2.show();

    }



}

回答1:

How big are the images? What handset are we talking about here?

I am betting that the images you're getting are not being scaled down before being displayed. I believe there are methods in LWUIT to scale down the size of an image. Remember to dispose of the temp image you create after adding the image to your form.