我正在疯狂尝试使用RSSReader组件处理rss请求错误。我像这样创建我的RssReader:
RSSReader r = new RSSReader();
r.setTargetContainer(c.getParent());
r.setUIID("RSSReader");
r.setURL("some feed url");
r.setProgressTitle("Fetching News Feed");
r.setHint("RSS Data Will Show Here");
r.setLimit(10);
NetworkManager.getInstance().start();
r.sendRequest();
myL x = new myL();
NetworkManager.getInstance().addErrorListener(x);
findRssContainer(c.getComponentForm()).removeComponent(findBtnLoadRss(c.getComponentForm()));
和myL
类编写如下:
class myL implements ActionListener
{
public void actionPerformed(ActionEvent ae) {
Container c = (Container)ae.getComponent(); //returns null pointer exception
findRssContainer(c).addComponent(findBtnLoadRss(c));
}
}
问题是ae.getComponent
为空,因此尝试调用findContainer
时出错。我已经尝试了ActionEvent的各种属性而没有成功。有没有人知道这个问题的解决方法?
感谢!!!
答案 0 :(得分:0)
看来这个问题比我想象的要简单,我终于通过这样做来解决它:
class myL implements ActionListener
{
public Form f;
public myL(Form frm)
{
f = frm;
}
public void actionPerformed(ActionEvent ae) {
if(findBtnLoadRss(f).getParent() != null)
{
findRssContainer(f).addComponent(findBtnLoadRss(f));
}
}
}
并使用myL
作为参数构建c.GetComponentForm()
。