Android Webview: “Uncaught TypeError: Cannot read property 'getItem' of null”

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

I am creating a simple android app which has a webview which should display a url. When I give the url as google.com or facebook.com it loads properly but when I give my url(qbo.intuit.com), it doesn't load and gives the "Uncaught TypeError: Cannot read property 'getItem' of null" error. I am pasting my code here well. I am using Compile sdk version: API 22: Android 5.1 (Lollipop), Version- Android Studio 1.4, Build Number: AI-141.2288178, Android SDK Tools: 24.4.0, jdk1.7.0_80. A similar question exists but it did not help me. Please help I am new to android. MainActivity.java

 @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      String url= "https://qbo.intuit.com/";     WebView view= (WebView) this.findViewById(R.id.webView);       final WebViewClient client = new WebViewClient() {          @Override         public boolean shouldOverrideUrlLoading(WebView view, String url) {             view.loadUrl(url);             return false;         }      };          WebSettings settings = view.getSettings();         settings.setJavaScriptEnabled(true);     view.setWebViewClient(client);         view.loadUrl(url);   } 

AndriodManifest.xml

<?xml version="1.0" encoding="utf-8"?> 

<uses-permission android:name="android.permission.INTERNET"/>  <application     android:allowBackup="true"     android:icon="@mipmap/ic_launcher"     android:label="@string/app_name"     android:theme="@style/AppTheme" >     <activity         android:name=".MainActivity"         android:label="@string/app_name">         <intent-filter>             <action android:name="android.intent.action.MAIN" />              <category android:name="android.intent.category.LAUNCHER" />         </intent-filter>     </activity> </application> 

回答1:

you need to do

WebSettings settings = webView.getSettings(); settings.setDomStorageEnabled(true); 

see details ERROR/Web Console: Uncaught TypeError: Cannot call method 'getItem' of null at http://m.youtube.com/:844



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!