0

私はブラックベリーの初心者です。HTTP接続を作成するためにブラックベリー9800シミュレーターを使用しました。次のコードを書きました。

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

}

それは完璧に動作します。しかし、突然、Blackberry9800からBlackberry8900Curveに切り替える必要があります。私はシミュレーターを使用して、それに同じコードを書きます。しかし、次の行でNullPointerExceptionが発生しました。

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

私はどこが間違っていますか?

4

1 に答える 1

1

ConnectionFactory.getConnection()はバージョン 5 以降でサポートされています。Blackberry 8900 のバージョンは 5.x または 4.x ですか? 4.xだと思います。

これを試すことができます: HTTPConnection httpConnector = (HttpConnection) Connector.open(url);

そして応答を得るには: httpConnector.setRequestMethod(HttpConnection.GET); InputStream in = httpConnector.openInputStream();

于 2011-05-30T07:52:06.620 に答える