android - how to check if webview URL contains a string? -


i trying make app share valid url only, else show toast. checking if url contains particular string. if yes, share link, however, getting exception-

public void sharevideo() {     string url = webview.geturl();     if (url.contains("play;_ylt=")) {         // video_is_being_played         intent shareintent = new intent(intent.action_send);         shareintent.settype("text/plain");         shareintent.putextra(intent.extra_text, url);         startactivity(intent.createchooser(shareintent, "share..."));     } else {         toast.maketext(getbasecontext(), "cannot share this",                 toast.length_long).show();     } } 

logs included-

 06-11 06:54:08.120: e/inputeventreceiver(9116): exception dispatching input event.     06-11 06:54:08.120: e/messagequeue-jni(9116): exception in messagequeue callback: handlereceivecallback     06-11 06:54:08.122: e/messagequeue-jni(9116): java.lang.nullpointerexception: attempt invoke virtual method 'boolean java.lang.string.contains(java.lang.charsequence)' on null object reference     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ com.example.myapp.mainactivity.sharevideo(mainactivity.java:446)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ com.example.myapp.mainactivity.onoptionsitemselected(mainactivity.java:428)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.app.activity.onmenuitemselected(activity.java:3694)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v4.app.fragmentactivity.onmenuitemselected(fragmentactivity.java:404)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.app.appcompatactivity.onmenuitemselected(appcompatactivity.java:185)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.windowcallbackwrapper.onmenuitemselected(windowcallbackwrapper.java:100)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.app.appcompatdelegateimplv7.onmenuitemselected(appcompatdelegateimplv7.java:655)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.menu.menubuilder.dispatchmenuitemselected(menubuilder.java:811)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.menu.menuitemimpl.invoke(menuitemimpl.java:152)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.menu.menubuilder.performitemaction(menubuilder.java:958)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.menu.menubuilder.performitemaction(menubuilder.java:948)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.view.menu.menupopuphelper.onitemclick(menupopuphelper.java:191)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.adapterview.performitemclick(adapterview.java:305)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.abslistview.performitemclick(abslistview.java:1206)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.abslistview$performclick.run(abslistview.java:3260)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.abslistview.ontouchup(abslistview.java:4068)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.abslistview.ontouchevent(abslistview.java:3830)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.support.v7.widget.listviewcompat.ontouchevent(listviewcompat.java:120)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.view.dispatchtouchevent(view.java:8488)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2400)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2093)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2406)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2107)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.widget.popupwindow$popupviewcontainer.dispatchtouchevent(popupwindow.java:1744)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.view.dispatchpointerevent(view.java:8683)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$viewpostimeinputstage.processpointerevent(viewrootimpl.java:4129)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$viewpostimeinputstage.onprocess(viewrootimpl.java:3995)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3603)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3569)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$asyncinputstage.forward(viewrootimpl.java:3686)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3577)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$asyncinputstage.apply(viewrootimpl.java:3743)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3603)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3569)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3577)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl.deliverinputevent(viewrootimpl.java:5813)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl.doprocessinputevents(viewrootimpl.java:5787)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl.enqueueinputevent(viewrootimpl.java:5758)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.viewrootimpl$windowinputeventreceiver.oninputevent(viewrootimpl.java:5903)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.view.inputeventreceiver.dispatchinputevent(inputeventreceiver.java:185)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.os.messagequeue.nativepollonce(native method)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.os.messagequeue.next(messagequeue.java:143)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ de.robv.android.xposed.xposedbridge.invokeoriginalmethodnative(native method)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ de.robv.android.xposed.xposedbridge.handlehookedmethod(xposedbridge.java:681)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.os.messagequeue.next(<xposed>)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.os.looper.loop(looper.java:122)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ android.app.activitythread.main(activitythread.java:5310)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ java.lang.reflect.method.invoke(native method)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ java.lang.reflect.method.invoke(method.java:372)     06-11 06:54:08.122: e/messagequeue-jni(9116):   @ com.android.internal.os.z     06-11 06:54:08.123: d/androidruntime(9116): shutting down vm     06-11 06:54:08.125: e/androidruntime(9116): fatal exception: main     06-11 06:54:08.125: e/androidruntime(9116): process: com.example.myapp, pid: 9116     06-11 06:54:08.125: e/androidruntime(9116): java.lang.nullpointerexception: attempt invoke virtual method 'boolean java.lang.string.contains(java.lang.charsequence)' on null object reference     06-11 06:54:08.125: e/androidruntime(9116):     @ com.example.myapp.mainactivity.sharevideo(mainactivity.java:446)     06-11 06:54:08.125: e/androidruntime(9116):     @ com.example.myapp.mainactivity.onoptionsitemselected(mainactivity.java:428)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.app.activity.onmenuitemselected(activity.java:3694)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v4.app.fragmentactivity.onmenuitemselected(fragmentactivity.java:404)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.app.appcompatactivity.onmenuitemselected(appcompatactivity.java:185)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.windowcallbackwrapper.onmenuitemselected(windowcallbackwrapper.java:100)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.app.appcompatdelegateimplv7.onmenuitemselected(appcompatdelegateimplv7.java:655)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.menu.menubuilder.dispatchmenuitemselected(menubuilder.java:811)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.menu.menuitemimpl.invoke(menuitemimpl.java:152)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.menu.menubuilder.performitemaction(menubuilder.java:958)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.menu.menubuilder.performitemaction(menubuilder.java:948)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.view.menu.menupopuphelper.onitemclick(menupopuphelper.java:191)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.adapterview.performitemclick(adapterview.java:305)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.abslistview.performitemclick(abslistview.java:1206)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.abslistview$performclick.run(abslistview.java:3260)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.abslistview.ontouchup(abslistview.java:4068)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.abslistview.ontouchevent(abslistview.java:3830)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.support.v7.widget.listviewcompat.ontouchevent(listviewcompat.java:120)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.view.dispatchtouchevent(view.java:8488)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2400)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2093)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewgroup.dispatchtransformedtouchevent(viewgroup.java:2406)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewgroup.dispatchtouchevent(viewgroup.java:2107)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.widget.popupwindow$popupviewcontainer.dispatchtouchevent(popupwindow.java:1744)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.view.dispatchpointerevent(view.java:8683)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$viewpostimeinputstage.processpointerevent(viewrootimpl.java:4129)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$viewpostimeinputstage.onprocess(viewrootimpl.java:3995)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3603)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3569)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$asyncinputstage.forward(viewrootimpl.java:3686)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3577)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$asyncinputstage.apply(viewrootimpl.java:3743)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.ondelivertonext(viewrootimpl.java:3603)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.forward(viewrootimpl.java:3569)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.apply(viewrootimpl.java:3577)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$inputstage.deliver(viewrootimpl.java:3550)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl.deliverinputevent(viewrootimpl.java:5813)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl.doprocessinputevents(viewrootimpl.java:5787)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl.enqueueinputevent(viewrootimpl.java:5758)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.viewrootimpl$windowinputeventreceiver.oninputevent(viewrootimpl.java:5903)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.view.inputeventreceiver.dispatchinputevent(inputeventreceiver.java:185)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.os.messagequeue.nativepollonce(native method)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.os.messagequeue.next(messagequeue.java:143)     06-11 06:54:08.125: e/androidruntime(9116):     @ de.robv.android.xposed.xposedbridge.invokeoriginalmethodnative(native method)     06-11 06:54:08.125: e/androidruntime(9116):     @ de.robv.android.xposed.xposedbridge.handlehookedmethod(xposedbridge.java:681)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.os.messagequeue.next(<xposed>)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.os.looper.loop(looper.java:122)     06-11 06:54:08.125: e/androidruntime(9116):     @ android.app.activitythread.main(activitythread.java:5310)     06-11 06:54:08.125: e/androidruntime(9116):     @ java.lang.reflect.method.invoke(native method)     06-11 06:54:08.125: e/androidruntime(9116):     @ java.lang.reflect.meth 

have checked if webview object initialized or exists in scope?

it wise check via toast object or debug message url receive, i.e. geturl() returns.

lastly, try using method .matches(string) instead of .contains(charsequence).


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -