Android加载webview 弹出错误
来源:互联网 发布:2016年最红的网络歌曲 编辑:程序博客网 时间:2024/05/16 14:48
项目中需要加载本地的json数据放到webview上显示,之前加载url的数据,都是新建一个线程然后加载图形,不过突然出现如下错误:
07-30 10:15:44.031: W/webview_proxy(3770): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
错误很明显是说webview的进程需要放到主线程里面来做,引入stack里的网页回答如下:
My Web view is not calling the javascript function it is returning warning like below. Can anybody suggest how to get rid of the below warning.
07-30 10:15:44.031: W/webview_proxy(3770): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
Below is my function.
public boolean onLongClick(View v){ System.out.println("dfdsf"); // Tell the javascript to handle this if not in selection mode //if(!this.isInSelectionMode()){ this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; //this.setJavaScriptEnabled(true); //} // Don't let the webview handle it return true;}
5 Answers
The warning is telling you everything. You are calling the webview methods directly. That means you are calling them on WebViewCoreThread. You have to call them on the UI Thread that means in the Activity which uses this webview.
Like:
WebView wv = (WebView)findViewById(id);wv.setJavaScriptEnabled(true);wv.setJavaScriptCanOpenWindowsAutomatically(true);wv.setPluginsEnabled(true);wv.loadUrl("javascript:android.selection.longTouch();");
As the warning says you are calling the webview methods in the WebViewCoreThread
. Thus modify your code like this,
public boolean onLongClick(View v){ YourActivity.this.runOnUiThread(new Runnable() { public void run() { this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } });}
// 加载历史数据到图形界面public void loadHisData(final int cycle, final String instname) {getProgressDialog().show();new Thread() {@Overridepublic void run() {try {hisDataList = TradeAPI.getInstance().queryHisData(StaticContext.CHART_INST,StaticContext.CHART_CYCLE_60MIN);if (hisDataList != null) {final String json = JSONUtil.getJSON4HistoryData(hisDataList);activity.runOnUiThread(new Runnable() {@Overridepublic void run() {first_chart_webview.loadUrl("javascript:resetMockTicks("+ json + ","+ hisDataList.size() + ",1,1)");}});}} finally {Runnable work = new Runnable() {@Overridepublic void run() {getProgressDialog().dismiss();}};getHandler().post(work);}}}.start();}
My Web view is not calling the javascript function it is returning warning like below. Can anybody suggest how to get rid of the below warning.
07-30 10:15:44.031: W/webview_proxy(3770): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
Below is my function.
public boolean onLongClick(View v){ System.out.println("dfdsf"); // Tell the javascript to handle this if not in selection mode //if(!this.isInSelectionMode()){ this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; //this.setJavaScriptEnabled(true); //} // Don't let the webview handle it return true;}
5 Answers
The warning is telling you everything. You are calling the webview methods directly. That means you are calling them on WebViewCoreThread. You have to call them on the UI Thread that means in the Activity which uses this webview.
Like:
WebView wv = (WebView)findViewById(id);wv.setJavaScriptEnabled(true);wv.setJavaScriptCanOpenWindowsAutomatically(true);wv.setPluginsEnabled(true);wv.loadUrl("javascript:android.selection.longTouch();");
wv.getSettings().setJavaScriptEnabled(true)
. Hope this solves your problem – ZeusNet Aug 24 '15 at 8:47 As the warning says you are calling the webview methods in the WebViewCoreThread
. Thus modify your code like this,
public boolean onLongClick(View v){ YourActivity.this.runOnUiThread(new Runnable() { public void run() { this.getSettings().setJavaScriptEnabled(true); this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); this.getSettings().setPluginsEnabled(true); this.loadUrl("javascript:android.selection.longTouch();"); mScrolling = true; } });}
- Android加载webview 弹出错误
- Android WebView 无法加载Https(或加载错误)
- webview加载时候弹出进度条
- android webview 加载进度和自定义404错误页面
- android webview加载网页时提示NET::ERR_CACHE_MISS的错误
- WebView加载网页无法弹出对话框
- Android WebView 加载资源
- Android WebView 加载网页
- Android webview加载url
- android webview加载网页
- Android webview 加载本地文件
- android webView 不能加载
- Android加载网页WebView
- android Webview加载优化
- Android WebView加载空白
- android webview 加载h5
- Android,WebView加载CookieSession
- Android-WebView加载网页
- [转载]微服务实战(二):使用API Gateway
- NetworkManager asks for password every time when i try to connect
- LeetCode : 4Sum [java]
- HTML5 data-* 自定义属性
- onclientclick和onclick区别
- Android加载webview 弹出错误
- uboot基本命令详解
- 【ShawnZhang】带你看蓝桥杯——算法训练Torry的困惑(基本型)
- MFS的MASTER启动出现错误
- 杂货铺
- oracle insert into 多个value
- HTML5新元素总结
- 一个优化程序效率的调试小技巧
- Hadoop-CentOS精简版搭建Hadoop集群
wv.getSettings().setJavaScriptEnabled(true)
. Hope this solves your problem – ZeusNet Aug 24 '15 at 8:47