Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to handle MalformedException #20

Open
vishalvishvakarma opened this issue Jun 11, 2020 · 5 comments
Open

unable to handle MalformedException #20

vishalvishvakarma opened this issue Jun 11, 2020 · 5 comments

Comments

@vishalvishvakarma
Copy link

I m getting this error and i am unable to handle it
plz help how to handle it i have tried my code with try catch but exception is occur in
your side which i cannot handle

java.lang.RuntimeException: An error occured while executing doInBackground()
java.lang.IllegalArgumentException: Malformed URL
java.net.MalformedURLException: Unknown protocol

@Ankur008
Copy link

@vishalvishvakarma did you got any solution?

@vishalvishvakarma
Copy link
Author

vishalvishvakarma commented Jun 16, 2020

I clone this project and added all the classes in my project and handle the exception
Which i m getting @Ankur008

@ririlya94
Copy link

ririlya94 commented Aug 6, 2020

@vishalvishvakarma @Ankur008 you can try this way, it prevents the app from crashing

 ArrayList<String> containedUrls = new ArrayList();
            Pattern pattern = Pattern.compile("(?<protocol>(http|ftp|https|ftps):\/\/)?(?<site>[\w\-_\.]+\.(?<tld>([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|arpa|asia|coop|info|jobs|mobi|museum|name|travel))+(?<port>:[0-9]+)?\/?)((?<resource>[\w\-\.,@^%:/~\+#]*[\w\-\@^%/~\+#])(?<queryString>(\?[a-zA-Z0-9\[\]\-\._+%\$#\~',]*=[a-zA-Z0-9\[\]\-\._+%\$#\~',]*)+(&[a-zA-Z0-9\[\]\-\._+%\$#\~',]*=[a-zA-Z0-9\[\]\-\._+%\$#\~',]*)*)?)?");
            Matcher urlMatcher = pattern.matcher("<your url link here>");

            while (urlMatcher.find()) {
                containedUrls.add(
                        "".substring(
                        urlMatcher.start(0),
                        urlMatcher.end(0)
                ));
            }

//then we check if contains url we are going to assign richlinkpreview
            if(containedUrls.size() > 0)
            {
//let's try again if it's url is valid
                try {
                    URL url = new URL(containedUrls.get(0));
                } catch (MalformedURLException e) {
                    System.out.println("The URL is not valid.");
                    System.out.println(e.getMessage());
                    return;
                }

richLinkView.setLink("https://stackoverflow.com", new ViewListener() {
                @Override
                public void onSuccess(boolean status) {}
                @Override
                public void onError(Exception e) {}
            });


            }

@PeggTime
Copy link

@ririlya94 what is the value of containedUrls arraylist? In the line number 3(

Matcher urlMatcher = pattern.matcher("");

), instead of "" , url value will come here?

@ririlya94
Copy link

ririlya94 commented Aug 25, 2020

@ririlya94 what is the value of containedUrls arraylist? In the line number 3(

Matcher urlMatcher = pattern.matcher("");

), instead of "" , url value will come here?

@PeggTime yes correct. Sorry for the confusion there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants