BlackBerry BrowserField IllegalStateException

发布于 2024-10-21 10:29:19 字数 1401 浏览 1 评论 0原文

我正在尝试与 field2.BrowserField 实现简单的用户交互:单击按钮时 BrowserField 加载 另一页,但我收到 IllegalStateException。

这是我的代码:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1");
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);
      ButtonField btn2 = new ButtonField("test2");
      btn2.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test2();                
        }
      });
      add(btn2);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {             
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

  private void test2() {
      synchronized (Application.getEventLock())
        {
         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
  }

}

I'm trying to implement simple user interaction with field2.BrowserField: when button is clicked BrowserField loads
another page, but I'm getting IllegalStateException.

here's my code:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1");
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);
      ButtonField btn2 = new ButtonField("test2");
      btn2.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test2();                
        }
      });
      add(btn2);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {             
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

  private void test2() {
      synchronized (Application.getEventLock())
        {
         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
  }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

第七度阳光i 2024-10-28 10:29:19

试试这个:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

  ButtonField btn1 = new ButtonField("test1");
  btn1.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test1();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn1);
  ButtonField btn2 = new ButtonField("test2");
  btn2.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test2();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn2);

  browser = new BrowserField();
  add(browser);

  //browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  test1("http://stackoverflow.com/");
}

  private void test1(final String url) {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {     
            //browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
            browser.requestContent(url + ";deviceside=true");
        }
    });

  }

//  private void test2() {
//      synchronized (Application.getEventLock())
//        {
//         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
//        }
//  }
}

Try this one:

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

  ButtonField btn1 = new ButtonField("test1");
  btn1.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test1();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn1);
  ButtonField btn2 = new ButtonField("test2");
  btn2.setChangeListener(new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        //test2();
        test1("http://www.blackberry.com/developers");
    }
  });
  add(btn2);

  browser = new BrowserField();
  add(browser);

  //browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  test1("http://stackoverflow.com/");
}

  private void test1(final String url) {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {     
            //browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
            browser.requestContent(url + ";deviceside=true");
        }
    });

  }

//  private void test2() {
//      synchronized (Application.getEventLock())
//        {
//         browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
//        }
//  }
}
萌辣 2024-10-28 10:29:19

哇,添加 browser.setFocus();做这个伎俩

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1", ButtonField.CONSUME_CLICK);
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {      
            browser.setFocus();
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

}

Wow, adding browser.setFocus(); do the trick

public class BrowserScreen extends MainScreen {
  private BrowserField browser;

  public BrowserScreen() {
      super();
      setTitle("Browser State example");

      ButtonField btn1 = new ButtonField("test1", ButtonField.CONSUME_CLICK);
      btn1.setChangeListener(new FieldChangeListener() {

        public void fieldChanged(Field field, int context) {
            test1();                
        }
      });
      add(btn1);

      browser = new BrowserField();
      add(browser);
      browser.requestContent("http://stackoverflow.com/" + ";deviceside=true;");
  }

  private void test1() {
      UiApplication.getUiApplication().invokeLater(new Runnable() {         
        public void run() {      
            browser.setFocus();
            browser.requestContent("http://www.blackberry.com/developers" + ";deviceside=true");
        }
    });

  }

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文