0

我希望我WebView加载我操纵的 HTML,它将保存在 /klw.html 中。之后我加载它mWebView.loadUrl("file:///android_asset/klw.html"); 但是当我在模拟器中尝试它时它说:“网页不可用”。我的错在哪里?我必须从另一个目录加载它吗?

这是我的代码:

public class Stundenplan extends Activity {

    String url = "http://info.tam.ch/display/timetable_external.php?school=klw&sem=54&class=26&week=16";
    Document document;

    public void main(String... args){
        try {
            document = Jsoup.connect(url).get();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        Element head = document.head();
        head.append("<link rel=\"stylesheet\" href=\"klw.css\">");
        String html = document.html();

        String charset = Jsoup.connect(url).response().charset();
        // ...
        try {
            Writer writer = new PrintWriter("/klw.html", charset);
            writer.write(html);
            writer.close();
        }
        catch (IOException e) {
            e.printStackTrace();
        } 
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        main();
        WebView mWebView;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mWebView = (WebView) findViewById(R.id.webView);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.getSettings().setDomStorageEnabled(true);
        mWebView.getSettings().setSupportZoom(true);
        mWebView.loadUrl("file:///android_asset/klw.html");
    }
}
4

1 回答 1

0

你有<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />确保正在写入文件吗?

您是否有<uses-permission android:name="android.permission.INTERNET">确保正在检索的 URI 没有被检索为 NULL 然后保存为空白 html?

于 2011-04-14T21:01:17.087 回答