android - Fatal Exception: java.lang.NullPointerException at MainFragment -
recently found out application crashes on devices. here crash:
java.lang.nullpointerexception @ com.zippyshare.search.free.fragment.mainfragment$3.loadfromassetswhite(mainfragment.java:501) @ com.zippyshare.search.free.fragment.mainfragment$3.shouldinterceptrequest(mainfragment.java:477) @ android.webkit.callbackproxy.shouldinterceptrequest(callbackproxy.java:1463) @ android.webkit.browserframe.shouldinterceptrequest(browserframe.java:964) @ android.webkit.jwebcorejavabridge.nativeservicefuncptrqueue(jwebcorejavabridge.java) @ android.webkit.jwebcorejavabridge.handlemessage(jwebcorejavabridge.java:113) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:177) @ android.webkit.webviewcore$webcorethread.run(webviewcore.java:1133) @ java.lang.thread.run(thread.java:856)
here crashing coode:
private webresourceresponse loadfromassetswhite(string assetpath, string mimetype, string encoding){ 501 line ------>assetmanager assetmanager = getactivity().getassets(); inputstream input; try { input = assetmanager.open("search-white.png"); return new webresourceresponse(mimetype, encoding, input); } catch (ioexception e) { log.e("web-app", "error loading " + assetpath + " assets: " + e.getmessage(), e); } return null; }
and here call method:
if (webviewurl != null && webviewurl.contains("results.html")) { return loadfromassetsblack("", "", ""); } else { 477 line--------------->return loadfromassetswhite("", "", ""); }
full webviewclient code:
webview.setwebviewclient(new webviewclient() { private boolean msuccess = true; @suppresswarnings("deprecation") @override public webresourceresponse shouldinterceptrequest(webview view, string url) { logcat.d("resource(pre) url: "+url); if (url.contains("adcash.com")){ return new webresourceresponse("text/plain", "utf-8", new bytearrayinputstream("".getbytes())); } else if (url.equals("search_box_icon.png")) { isurlready = false; webviewurl = null; try { mainactivity.mainactivity.runonuithread(new runnable() { @override public void run() { webviewurl = webview.geturl(); isurlready = true; } }); } catch (exception ex) { ex.printstacktrace(); isurlready = true; } while(!isurlready); isurlready = false; if (webviewurl != null && webviewurl.contains("results.html")) { return loadfromassetsblack("", "", ""); } else { return loadfromassetswhite("", "", ""); } } logcat.d("resource(post) url: "+url); return super.shouldinterceptrequest(view, url); } private webresourceresponse loadfromassetsblack(string assetpath, string mimetype, string encoding){ assetmanager assetmanager = getactivity().getassets(); inputstream input; try { input = assetmanager.open("search-black.png"); return new webresourceresponse(mimetype, encoding, input); } catch (ioexception e) { log.e("web-app", "error loading " + assetpath + " assets: " + e.getmessage(), e); } return null; } private webresourceresponse loadfromassetswhite(string assetpath, string mimetype, string encoding){ assetmanager assetmanager = getactivity().getassets(); inputstream input; try { input = assetmanager.open("search-white.png"); return new webresourceresponse(mimetype, encoding, input); } catch (ioexception e) { log.e("web-app", "error loading " + assetpath + " assets: " + e.getmessage(), e); } return null; }
if need more details, can check crashalytics report: http://crashes.to/s/e0975fe822c thank in advance help.
fix suggested @chandra:
private webresourceresponse loadfromassetswhite(string assetpath, string mimetype, string encoding){ context context = getactivity(); if(context == null) { context = mainactivity.mainactivity; } assetmanager assetmanager = context.getassets(); inputstream input; try { input = assetmanager.open("search-white.png"); return new webresourceresponse(mimetype, encoding, input); } catch (ioexception e) { log.e("web-app", "error loading " + assetpath + " assets: " + e.getmessage(), e); } return null; }
Comments
Post a Comment