2011-09-29 1 views
0

검은 딸기 응용 프로그램을 개발 중입니다. 화면에지도가 있습니다. 내 웹 서비스에서 가져 오는 새로운 데이터로지도의 데이터를 새로 고침하고 싶습니다. 스레드에서 BlockingSenderDestination을 사용하고 있습니다. 내가 "데이터 가져 오기"요청하면 그 새 데이터를 반환합니다. 문제 없어. 인수를 전달하는 내 maprefresh 함수를 호출하려면 invokelater 함수를 사용하고 있지만 난 예외가 있습니다.새 데이터로 블랙 베리 화면 갱신

내 문제를 해결하기위한 제안이나 더 좋은 방법은 없나요?

public class MyMainScreen extends MainScreen { 
    RichMapField map; 
    MyClassList _myclassList; 
    private String _result2t; 

    public MyMainScreen(JSONArray jarray) 
    { 


    map = MapFactory.getInstance().generateRichMapField(); 
     MapDataModel mapDataModel = map.getModel(); 

     JSONObject json = null; 
      boolean getdata=false; 
      for (int i=0;i<jarray.length();i++) 
      { 

       try 
       { 
      json=jarray.getJSONObject(i); 
       getdata=true; 
       } 
       catch(Exception e) 
       { 

       } 

       if(getdata) 
       { 
        try 
        {      
        double lat = Double.valueOf(json.getString("LATITUDE")).doubleValue(); 
       double lng = Double.valueOf(json.getString("LONGITUDE")).doubleValue();    
       String myclassdata= json.getString("myclassdata").toString(); 
       MyClass ben = new MyClass(myclassdata);     
       _myclassList.addElement(ben);  
       MapLocation termimapitem = new MapLocation(lat, lng, "",""); 
       mapDataModel.add((Mappable)termimapitem,"1"); 
        } 

        catch(Exception e) 
        { 
         //mesajGoster("Hatalı Veri"); 
        } 

       } 
       else 
       { 
        //mesajGoster("Listeye Eklenemedi"); 
       } 
      } 
    } 


    private void GetTerminals(String companyNo){ 
     final String companyNoR= companyNo; 
     Thread t = new Thread(new Runnable() 
     { 
      public void run() 
      { 
       Message response = null; 
       String uriStr = "http://webservice";     
       BlockingSenderDestination bsd = null; 
       try 
       { 
        bsd = (BlockingSenderDestination) 
           DestinationFactory.getSenderDestination 
            ("o", URI.create(uriStr)); 
        if(bsd == null) 
        { 
         bsd = 
          DestinationFactory.createBlockingSenderDestination 
           (new Context("o"), 
           URI.create(uriStr) 
           ); 
        } 

        response = bsd.sendReceive(); 

        if(response != null) 
        { 
         BSDResponse(response,companyNoR); 
        } 
       } 
       catch(Exception e) 
       { 
       } 
       finally 
       { 
        if(bsd != null) 
        { 
         bsd.release(); 
        } 
       } 
      } 

     }); 
     t.start(); 

    } 

    private void BSDResponse(Message msg,final String companyNo) 
    { 

     if (msg instanceof ByteMessage) 
     { 
      ByteMessage reply = (ByteMessage) msg; 
      _result2t = (String) reply.getStringPayload(); 
     } else if(msg instanceof StreamMessage) 
     { 
      StreamMessage reply = (StreamMessage) msg; 
      InputStream is = reply.getStreamPayload(); 
      byte[] data = null; 
      try { 
       data = net.rim.device.api.io.IOUtilities.streamToBytes(is); 
      } catch (IOException e) { 
       // process the error 
      } 
      if(data != null) 
      { 
       _result2t = new String(data); 
      } 
     } 
     try { 
       final JSONArray jarray= new JSONArray(_result2t);    
      final String username=_userName; 
      UiApplication.getUiApplication().invokeLater(new Runnable() { 
        public void run() { 
         Dialog.alert("The Toolbar i"); 
         Yenile(jarray); 
        } 

       }); 

     } catch (JSONException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
    } 



    private void Yenile(JSONArray jarray){ 
     MapDataModel mapDataModel = map.getModel(); 
     mapDataModel.remove("1"); 
     map.getMapField().update(true); 
     _terminalList = new TerminalList(); 
     map= MapFactory.getInstance().generateRichMapField(); 
     MapDataModel mapDataModel = map.getModel(); 
     JSONObject json = null; 
     boolean getdata=false; 
     for (int i=0;i<jarray.length();i++) 
     { 

      try 
      { 
     json=jarray_terminaller.getJSONObject(i); 
      getdata=true; 
      } 
      catch(Exception e) 
      { 

      } 

      if(getdata) 
      { 
       try 
       {      

       double lat = Double.valueOf(json.getString("LATITUDE")).doubleValue(); 
       double lng = Double.valueOf(json.getString("LONGITUDE")).doubleValue(); 

       String myclassdata= json.getString("myclassdata").toString(); 
       MyClass ben = new MyClass(myclassdata);     
       _myclassList.addElement(ben);  
       MapLocation termimapitem = new MapLocation(lat, lng, "",""); 
       mapDataModel.add((Mappable)termimapitem,"1"); 
       } 

       catch(Exception e) 
       { 
        //mesajGoster("Hatalı Veri"); 
       } 

      } 
      else 
      { 
       //mesajGoster("Listeye Eklenemedi"); 
      } 
     } 


    } 
} 
+1

디버거를 사용하여 오류가 발생한 행을 가리 킵니다. –

답변

0

내 질문에 대한 해결책을 찾았습니다. 나는 새로운 실행 방법을 통해 그것을 전송 된 데이터를 가져 오는 후

은 :

UiApplication.getUiApplication().invokeLater(new Runnable() { 
public void run() { 
     MyFunction(jarray); 
     }}); 

하지만 난 메인 스레드와 동기화 할 필요가 있었다. 해결책 :

UiApplication.getUiApplication().invokeLater(new Runnable() { 
       public void run() { 
        synchronized(Application.getEventLock()) { 
         Yenile(jarray); 
        } 

       } 

      }); 
0

화면을 새로 고치려면 : 다음과 같이 수행 여기

내 코드입니다

public class LoadingScreen extends MainScreen{ 
LoadingScreen() 
{ 
    createGUI(); 
} 
public void createGUI() 
{ 
    //Here you write the code that display on screen; 
}} 

을 우리는이 화면을 생성하는 실제 방법입니다 알고; 이제 다음과 같은 화면 쓰기 새로 고칠 경우

: Thread.sleep를 한 후 실행 방법 위의 세 줄 (10000)를 작성하는 방법 더 나은 InvokeLater에 대신 쓰기의

deleteAll(); 
invalidate(); 
createGUI();//here it creates the screen with new data. 

을;

의심되는 점이 있으시면 stackOverFlow 채팅 룸 이름은 "Life for Blackberry"이며 귀하의 의문점을 명확히 해줍니다.