我可以在WebView
中加载网址。但是,如果我执行某些操作(例如点击事件),我会在LogCat
中收到以下错误:
Unable to get value of the property 't': object is null or undefinedundefined
但是如果我从模拟器的浏览器中执行某些事件,它就可以正常工作。
以下是基于post:
的代码public class MainActivity extends Activity {
WebView mWebview = null;
String URL = "********"; // Masked intentionally.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main); //Not required as per comment given by Raghunandan.
mWebview = new WebView(this);
mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
final Activity activity = this;
mWebview.setWebChromeClient(new WebChromeClient());
mWebview.setWebViewClient(new WebViewClient() {
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
}
});
mWebview .loadUrl(URL);
setContentView(mWebview );
}
}
注意:网页是使用AngularJS
开发的。
我在Manifiest.xml
中添加了以下属性:
<uses-permission android:name="android.permission.INTERNET" />