0

我正在尝试在 LWUIT 中打开一个外部 HTML 文档,但我有一个例外

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

并且该类正在实现 DocumentRequestHandler

这是方法的实现

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

1 回答 1

0

我使用了 LWUIT 演示附带的浏览器代码,它是用于浏览器的,而且这个博客对我有很大帮助

http://codenameone.blogspot.com/2011/08/lwuit-15-released-finally.html

于 2012-06-28T11:56:12.087 回答