2012-06-25 31 views
0

我试图打开LWUIT外部HTML文件,但我有一个例外在LWUIT

htmlC = new HTMLComponent(this); 
htmlC.setPage(formURL); 

和类实现DocumentRequestHandler

,并打开外部HTML文档,这是实施方法

public InputStream resourceRequested(DocumentInfo di) { 
     final String url = di.getUrl(); 
     final boolean isPostRequest = di.isPostRequest(); 

     new Thread(new Runnable() { 
      public void run() { 
       in = getExternalData(url, isPostRequest); 
      } 
     }).start(); 


     return in; 
    } 

    private InputStream getExternalData(String url, boolean isPostRequest) { 
     if (url.startsWith("http://") == false) { 
      return getErrorStream("This handler handles http only."); 
     } 

     if (isPostRequest) { 
      return getErrorStream("GET requests only please!"); 
     } 

     try { 

      connection = (HttpConnection) Connector.open(url); 

      connection.setRequestMethod(HttpConnection.GET); 
      int resCode = connection.getResponseCode(); 

      if (resCode == connection.HTTP_OK) { 
       sb = new StringBuffer(); 
       in = connection.openDataInputStream(); 
       int chr; 

       while ((chr = in.read()) != -1) { 
        sb.append((char) chr); 
       } 

       System.out.println("sb : " + sb); 
       connection.close(); 
       return in; 
      } else { 
       return getErrorStream("Error Opening HTTP Connection."); 
      } 

     } catch (IOException ex) { 
      ExceptionController.printExceptionData("ExternalHTMLForm", "getExternalData", ex.getMessage()); 
      return getErrorStream(ex.getMessage()); 
     } finally { 
     } 

    } 

    // To print error message incase not able to open HTML file 
    private InputStream getErrorStream(String err) { 
     err = "<html><body>" + err + "</body></html>"; 
     ByteArrayInputStream bais = new ByteArrayInputStream(err.getBytes()); 
     return bais; 
    } 

和我有以下异常

Uncaught exception: java.lang.UnsupportedOperationException: Not supported yet. 
    at com.veripark.view.ui.ExternalHTMLForm.parsingError(ExternalHTMLForm.java:233) 
    at com.sun.lwuit.html.HTMLComponent.streamReady(), bci=210 
    at com.sun.lwuit.html.HTMLComponent$2.run(HTMLComponent.java:968) 
+0

请你告诉我,在这行的例外是投掷? –

回答