2010-06-07 4 views
0

Blackberry 기술 자료에서 샘플 응용 프로그램을 발견했습니다.Blackberry XML Parsing 응용 프로그램이 작동하지 않습니다.

내 이클립스 플러그인에 그 샘플 응용 프로그램을 넣어 가지고, 그리고 코드는 다음과 같다 해당 응용 프로그램에서

:

import javax.microedition.io.*; 
import net.rim.device.api.ui.*; 
import net.rim.device.api.ui.component.*; 
import net.rim.device.api.ui.container.*; 
import net.rim.device.api.system.*; 
import net.rim.device.api.xml.parsers.*; 
import org.w3c.dom.*; 
import org.xml.sax.*; 

class XML_Parsing_Sample extends UiApplication { 
    // creating a member variable for the MainScreen 
    MainScreen _screen = new MainScreen(); 
    // string variables to store the values of the XML document 
    String _node, _element; 
    Connection _connectionthread; 

    public static void main(String arg[]) { 
     XML_Parsing_Sample application = new XML_Parsing_Sample(); 
     // create a new instance of the application 
     // and start the application on the event thread 
     application.enterEventDispatcher(); 
    } 

    public XML_Parsing_Sample() { 
     _screen.setTitle("XML Parsing");// setting title 
     _screen.add(new RichTextField("Requesting.....")); 
     _screen.add(new SeparatorField()); 
     pushScreen(_screen); // creating a screen 
     // creating a connection thread to run in the background 
     _connectionthread = new Connection(); 
     _connectionthread.start();// starting the thread operation 
    } 

    public void updateField(String node, String element) { 
     // receiving the parsed node and its value from the thread 
     // and updating it here 
     // so it can be displayed on the screen 
     String title = "My App"; 
     _screen.add(new RichTextField(node + " : " + element)); 

     if (node.equals(title)) { 
      _screen.add(new SeparatorField()); 
     } 
    } 

    private class Connection extends Thread { 
     public Connection() { 
      super(); 
     } 

     public void run() { 
      // define variables later used for parsing 
      Document doc; 
      StreamConnection conn; 

      try { 
       // providing the location of the XML file, 
       // your address might be different 
       conn = (StreamConnection) Connector 
         .open("http://www.sufalamtech.com/demo/moviewebservice/Test.xml"); 
       // next few lines creates variables to open a 
       // stream, parse it, collect XML data and 
       // extract the data which is required. 
       // In this case they are elements, 
       // node and the values of an element 
       DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory 
         .newInstance(); 
       DocumentBuilder docBuilder = docBuilderFactory 
         .newDocumentBuilder(); 
       docBuilder.isValidating(); 
       doc = docBuilder.parse(conn.openInputStream()); 
       doc.getDocumentElement().normalize(); 
       NodeList list = doc.getElementsByTagName("*"); 
       _node = new String(); 
       _element = new String(); 
       // this "for" loop is used to parse through the 
       // XML document and extract all elements and their 
       // value, so they can be displayed on the device 

       for (int i = 0; i < list.getLength(); i++) { 
        Node value = list.item(i).getChildNodes().item(0); 
        _node = list.item(i).getNodeName(); 
        _element = value.getNodeValue(); 
        updateField(_node, _element); 
       }// end for 
      }// end try 
      // will catch any exception thrown by the XML parser 
      catch (Exception e) { 
       Dialog.alert("exception = " + e); 
      } 
     }// end connection function 
    }// end connection class 
}// end XML_Parsing_Sample 

을하지만이 응용 프로그램을 실행하고 때, 시뮬레이터 그냥 나에게 레이블이있는 빈 화면을 보여주는 요청 중 ...

아무도 도와주세요.

미리 감사드립니다 ...

+0

디버그 모드를 사용해 보셨습니까? 실행 설정에서 시뮬레이터로 MDS를 열었습니까? –

+0

안녕하세요, Michael B. 답변에 감사드립니다. 그것은 나를 위해 일한다 !! 그러나 아직도 나는 이클립스 플러그인에 몇 가지 중단 점을 넣어 내 bb 응용 프로그램을 디버깅 할 수 있는지 알고 싶습니다. 일부 줄에 중단 점을 넣으려고 시도한 다음 실행 -> 디버그 ...를 선택합니다. 그러나 여전히이 옵션은 디버그 모드가 아닌 응용 프로그램을 실행합니다. – Nirmal

답변

1

는이

public void updateField(String node, String element) { 
    // receiving the parsed node and its value from the thread 
    // and updating it here 
    // so it can be displayed on the screen 
    //Don't forget to add this next line when called from a thread 
    synchronized (UiApplication.getEventLock()) { 
     String title = "My App"; 
     _screen.add(new RichTextField(node + " : " + element)); 

     if (node.equals(title)) { 
      _screen.add(new SeparatorField()); 
     } 
     } 
} 

이 동기화 (UiApplication.getEventLock()), 당신은 UI에 액세스하는 데이 때마다 스레드 시도 정말 중요한 필요가있다 봅니다.

더 많은 솔루션이 있습니다. documentation

관련 문제