-2

java.lang.ArrayIndexOutOfBoundsException: at com.example.fragments.Hot$4.shouldOverrideUrlLoading(Hot.java:197) at com.android.webview.chromium.WebViewContentsClientAdapter.shouldOverrideUrlLoading(WebViewContentsClientAdapter.java:357) at org.chromium.android_webview.AwContentsClient.shouldIgnoreNavigation(AwContentsClient.java:168) at org.chromium.android_webview.AwContentsClientBridge.shouldOverrideUrlLoading(AwContentsClientBridge.java:352) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method:0) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:41) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:7406) at java.lang.reflect.Method.invoke(Native Method:0) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

Here is my Code:

  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 Answers1

0

Problem is this piece of code

String splitted=separated[1];

whenever you are dealing with array , it is safe to do a check before accessing the element in array.Something like

if(separated.length>2){
// do your stuff here
 String splitted=separated[1];
}else{
//handle failure case here
}
Nitin Mesta
  • 1,504
  • 19
  • 32