problem in StreamConnection blackberry

浪尽此生 提交于 2020-01-07 04:46:11

问题


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 the above code is not working in device? Thanks in advance..


回答1:


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");

For more information:

http://supportforums.blackberry.com/t5/Java-Development/Sample-HTTP-Connection-code-and-BIS-B-Access/td-p/653175



来源:https://stackoverflow.com/questions/5063335/problem-in-streamconnection-blackberry

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!