2017-06-01 78 views
-2

java.lang.ArrayIndexOutOfBoundsException網頁視圖方法shouldOverrideUrlLoading: 在com.example.fragments.Hot $ 4.shouldOverrideUrlLoading(Hot.java:197)在com.android.webview.chromium.WebViewContentsClientAdapter .org位於org.chromium.base的org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:352)上的org.chromium.android_webview.AwContentsClient.shouldIgnoreNavigation(AwContentsClient.java:168).shouldOverrideUrlLoading(WebViewContentsClientAdapter.java:357)。在android.os.Handler.dispatchMessage(Handler.java:102)處的android.os.Looper.loop處的org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41)處的SystemMessageHandler.nativeDoRunLoopOnce(本地方法:0) Looper.java:148)at android.app.ActivityThread.main(ActivityThread.java:7406)at java.l com.android.internal.os.ZygoteInit上的ang.reflect.Method.invoke(Native Method:0)在com.android.internal.os.ZygoteInit.main(ZygoteInit.java)上的$ MethodAndArgsCaller.run(ZygoteInit.java:1230) :1120)java.lang.ArrayIndexOutOfBoundsException:使用機器人

這裏是我的代碼:

hot_webview.setWebViewClient(new WebViewClient() 
    { 

     public boolean shouldOverrideUrlLoading(WebView view, String url) 
     { 

      String checkurl = url; 
      String[] separated = checkurl.split("="); 
      String splitted=separated[1]; 


      Log.i("iaminh", " shouldOverrideUrlLoading called"); 

      boolean installed = appInstalledOrNot(splitted); 
      if(installed) 
      { 

       Intent LaunchIntent = getActivity().getPackageManager() 
         .getLaunchIntentForPackage(splitted); 
       startActivity(LaunchIntent); 


       hot_webview.loadUrl(Hot_url); 

      } else 
      { 


       try { 
        startActivity(new Intent(Intent.ACTION_VIEW, Uri 
          .parse(market_url + splitted))); 

        hot_webview.loadUrl(Hot_url); 

       } catch (ActivityNotFoundException anfe) 
       { 
        startActivity(new Intent(
          Intent.ACTION_VIEW, 
          Uri.parse(playstore_url + splitted))); 

        hot_webview.loadUrl(Hot_url); 
       } 

      } 






      return false; 
     } 

    }); 
+1

後期片段代碼 –

+0

請分享全部代碼 –

+0

我編輯我的問題,請再次審查。 –

回答

0

問題是這段代碼

String splitted=separated[1]; 

每當你面對的陣列,它是安全的訪問元素之前做的檢查像

if(separated.length>2){ 
// do your stuff here 
String splitted=separated[1]; 
}else{ 
//handle failure case here 
}