HttpConnection 黑莓 8900

发布于 2024-11-10 13:30:41 字数 2211 浏览 1 评论 0原文

我是黑莓的新人。我使用黑莓 9800 模拟器创建 HTTP 连接。我写了以下代码。

    public MyScreen()
{        
    // Set the displayed title of the screen       
    setTitle("Hello");
    ConnectionFactory connFact = new ConnectionFactory();
    ConnectionDescriptor connDesc;
    connDesc = connFact.getConnection("http://whistlersbest.net/api/categories.php?parent_id=0");
    System.out.println("hello " + connFact);
    if (connDesc != null)
    {
        HttpConnection httpConn;
        httpConn = (HttpConnection)connDesc.getConnection();
        try
        {
            in = httpConn.openInputStream();

            int ii;
            while((ii=in.read()) != -1){

              strbuffer = strbuffer + (char)ii;
            }
         } 
         catch (IOException e) 
         {
           System.err.println("Caught IOException: " 
                + e.getMessage());
         }
    }
    setTitle("Whistlers Best");
    System.out.println("set Title");
    xmlHandler xm = new xmlHandler(strbuffer);
    category = xm.getCategory();
    System.out.println("category set");
    String[] arr = new String[category.getIds().size()];
    System.out.println("Array " + arr.length);
    list = new ObjectListField(){
        protected boolean navigationClick(int status, int time) {
            //UiApplication.getUiApplication().pushScreen(new SubCategories(category.getIds().elementAt(list.getSelectedIndex()).toString(),"1",category.getNames().elementAt(list.getSelectedIndex()).toString()));
            return false;

        }

    };
    for(int y = 0; y<category.getIds().size() ; y++){
        arr[y] = (String)category.getNames().elementAt(y);
        System.out.println("string: "+arr[y]);
    }


    list.set(arr);
    VerticalFieldManager hfm = new VerticalFieldManager(Manager.FIELD_HCENTER);
    hfm.add(new LabelField("Categories",
            Field.FIELD_HCENTER));
    hfm.add(list);
    list.setChangeListener(this);
    add(hfm);

}

它工作完美。但突然我需要从 Blackberry 9800 切换到 Blackberry 8900 Curve。我使用模拟器并为其编写相同的代码。但我在以下行得到了 NullPointerException:

connDesc = connFact.getConnection("http://whistlersbest.net/api/categories.php?parent_id=0");

我错在哪里?

i am new at blackberry., I used blackberry 9800 simulator to create an HTTP connection. I wrote following code.

    public MyScreen()
{        
    // Set the displayed title of the screen       
    setTitle("Hello");
    ConnectionFactory connFact = new ConnectionFactory();
    ConnectionDescriptor connDesc;
    connDesc = connFact.getConnection("http://whistlersbest.net/api/categories.php?parent_id=0");
    System.out.println("hello " + connFact);
    if (connDesc != null)
    {
        HttpConnection httpConn;
        httpConn = (HttpConnection)connDesc.getConnection();
        try
        {
            in = httpConn.openInputStream();

            int ii;
            while((ii=in.read()) != -1){

              strbuffer = strbuffer + (char)ii;
            }
         } 
         catch (IOException e) 
         {
           System.err.println("Caught IOException: " 
                + e.getMessage());
         }
    }
    setTitle("Whistlers Best");
    System.out.println("set Title");
    xmlHandler xm = new xmlHandler(strbuffer);
    category = xm.getCategory();
    System.out.println("category set");
    String[] arr = new String[category.getIds().size()];
    System.out.println("Array " + arr.length);
    list = new ObjectListField(){
        protected boolean navigationClick(int status, int time) {
            //UiApplication.getUiApplication().pushScreen(new SubCategories(category.getIds().elementAt(list.getSelectedIndex()).toString(),"1",category.getNames().elementAt(list.getSelectedIndex()).toString()));
            return false;

        }

    };
    for(int y = 0; y<category.getIds().size() ; y++){
        arr[y] = (String)category.getNames().elementAt(y);
        System.out.println("string: "+arr[y]);
    }


    list.set(arr);
    VerticalFieldManager hfm = new VerticalFieldManager(Manager.FIELD_HCENTER);
    hfm.add(new LabelField("Categories",
            Field.FIELD_HCENTER));
    hfm.add(list);
    list.setChangeListener(this);
    add(hfm);

}

It works perfectly. But suddenly I need to switch from Blackberry 9800 to Blackberry 8900 Curve. I use simulator and write the same code to that. But I got NullPointerException at line:

connDesc = connFact.getConnection("http://whistlersbest.net/api/categories.php?parent_id=0");

Where I am wrong?

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

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

发布评论

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

评论(1

星光不落少年眉 2024-11-17 13:30:41

版本5之后支持ConnectionFactory.getConnection()。Blackberry 8900版本是5.x还是4.x?我认为是4.x。

你可以试试这个:
HTTPConnection httpConnector = (HttpConnection) Connector.open(url);

并获取响应:
httpConnector.setRequestMethod(HttpConnection.GET);
输入流 = httpConnector.openInputStream();

ConnectionFactory.getConnection() is supported after version 5. Is Blackberry 8900 version is 5.x or 4.x? I think it is 4.x.

You can try this:
HTTPConnection httpConnector = (HttpConnection) Connector.open(url);

And to get response:
httpConnector.setRequestMethod(HttpConnection.GET);
InputStream in = httpConnector.openInputStream();

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