在黑莓的StreamConnection问题 [英] problem in StreamConnection blackberry

查看:267
本文介绍了在黑莓的StreamConnection问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到问题的设备与此code将其显示黑屏,但它在模拟运作良好。可以请你帮我理清问题....

I am getting problem in device with this code it showing blank screen, But it worked well in simulator. can you please help me to sort out the problem....

package test;

import java.io.DataInputStream;

import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;

import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class HomeScreen extends UiApplication{


    public static void main(String args[]){
        new HomeScreen().enterEventDispatcher();
    }
    public HomeScreen(){
        super();
        pushScreen(new MyScreen());
    }
}

class MyScreen extends MainScreen{
    private VerticalFieldManager vfm;
    public MyScreen(){
        super();
        vfm = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL){
            protected void paintBackground(Graphics graphics) 
            {        
                graphics.setBackgroundColor(0xBACd22);
                graphics.clear();
            }

            protected void sublayout(int width, int height) {
                super.sublayout(width, height);
                setExtent(Display.getWidth(),Display.getHeight());
            }
        };
        add(vfm);
        Thread t = new Thread(new Runnable(){
            public void run(){
                CallService();
            }
        });t.start();
    }

    private void CallService(){
        final StreamConnection streamConn;
            try {
                streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml");
                            LabelField applicationTitle = new LabelField("XML Parser");
                            setTitle(applicationTitle);
                            final DataInputStream _inputStream = new DataInputStream(streamConn.openInputStream());
                            UiApplication.getUiApplication().invokeLater(new Runnable(){
                                public void run(){
                                    Dialog.alert("Test" +_inputStream );
                                }
                            });
            } catch (Exception e) {
                e.printStackTrace();
            }


    }
}

y中的上述code未在设备工作?在此先感谢..

y the above code is not working in device? Thanks in advance..

推荐答案

您需要根据您所使用的连接类型(WIFI / BES / BIS / WAP2 / TCP)来追加URL参数。

You need to append URL parameter according to connection type (WiFi/BES/BIS/WAP2/TCP) you are using.

For example if you are using BES connection:

    streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=false");

and if your are using WiFi:

    streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=true;interface=wifi");

and For WAP2/TCP:

        streamConn = (StreamConnection)Connector.open("http://www.bankofcanada.ca/rss/fx/noon/fx-noon-all.xml;deviceside=true");

有关详细信息:

<一个href=\"http://supportforums.blackberry.com/t5/Java-Development/Sample-HTTP-Connection-$c$c-and-BIS-B-Access/td-p/653175\" rel=\"nofollow\">http://supportforums.blackberry.com/t5/Java-Development/Sample-HTTP-Connection-$c$c-and-BIS-B-Access/td-p/653175

这篇关于在黑莓的StreamConnection问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆