开发者

Cannot access provider class's methods

public final class BrowserTopComponent extends TopComponent implements ActionListener, ChangeListener, LookupListener{

    public BrowserTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(BrowserTopComponent.class, "CTL_BrowserTopComponent"));
        setToolTipText(NbBundle.getMessage(BrowserTopComponent.class, "HINT_BrowserTopComponent"));
//        setIcon(ImageUtilities.loadImage(ICON_PATH, true));

        Browser1 fff = new Browser1();
        associateLookup(Lookups.singleton(fff));
    }

    private Lookup.Result result = null;

    @Override
    public void componentOpened() {
        result = Utilities.actionsGlobalContext().lookupResult(Browser1.class);
        result.addLookupListener (this);
    }

    @Override
    public void componentClosed() {
        result.removeLookupListener (this);
        result = null;
    }

  private void navButtonActionPerformed(java.awt.event.ActionEvent evt) {
    fff.navgiateTo(); // NET BEAN COMPLAINS AT THIS LINE.
    }

any possible reasons why I cannot use fff.navigateTo(); But when fff.navigateTo() is inside the constructor of BrowserTopComponent, it works fine! So why can I not have it outside the constructor ?

In my Browser module (which loads 3rd party JAR), I have the following class:

package my.app.browser
import bunch.of.3rd.party.stuff
public class Browser1 {

    private String url;

    public void nav开发者_开发技巧igateTo() {

        System.out.println(url);
    }
}


This looks like a scoping issue. fff is declared locally in the constructor. In navButtonActionPerformed, it isn't declared at all. This might be due to how you snipped the code, but if the error message implies that fff is not declared, try declaring "Browser fff" at the class level. For instance,

class BrowserTopComponent ... {

  Browswer fff = new Browser();

  BrowserTopComponent() {
    initComponents();
  }

  private void navButtonActionPerformed(ActionEvent evt) {
    fff.navigateTo();
  }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜