如何将文档转换为字符串而无例外?
我使用 javascriptInterface 和 jsoup 从 url 中获取 html 字符串,然后加载到 WebView 在WebView中的单击元素上,但是问题是,单击后,应用程序崩溃并抛出异常“错误转换为字符串” 我尝试了许多答案如何将文档转换为 string ,但对我没有任何帮助。 请让我知道我的代码中有什么问题...
WebView urlview = findViewById(R.id.urlview);
String newsUrlToShare;
Thread HtmlParser = new Thread(){
public void run(){
try {
Document doc = Jsoup.connect(newsUrlToShare).followRedirects(false).timeout(0).method(Connection.Method.GET).get();
String body = doc.html();
urlview.loadDataWithBaseURL("https://google.com",body,"text/html","utf-8",null);
}catch(Exception ex) {
throw new RuntimeException("Error Converting to String",ex);
}
}
};
private final class jsInterface{
@JavascriptInterface
public final void openNews(String url){
urlview.post(() -> {
if(!url.equals("")){
BrowserOpened = false;
newsUrlToShare = url;
HtmlParser.start();
}
});
}
}
I use JavascriptInterface and JSOUP to get HTML string from URL and load into WebView on click element inside webView, but problem is that after click app is crashing and throw in exception "Error Converting to String"
I tried many answears how to convert Document to String but nothing worked for me.
Please let me know what is wrong in my code...
WebView urlview = findViewById(R.id.urlview);
String newsUrlToShare;
Thread HtmlParser = new Thread(){
public void run(){
try {
Document doc = Jsoup.connect(newsUrlToShare).followRedirects(false).timeout(0).method(Connection.Method.GET).get();
String body = doc.html();
urlview.loadDataWithBaseURL("https://google.com",body,"text/html","utf-8",null);
}catch(Exception ex) {
throw new RuntimeException("Error Converting to String",ex);
}
}
};
private final class jsInterface{
@JavascriptInterface
public final void openNews(String url){
urlview.post(() -> {
if(!url.equals("")){
BrowserOpened = false;
newsUrlToShare = url;
HtmlParser.start();
}
});
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论