java - This method must return a result of type InputStream -
i'm getting error stating this method must return result of type inputstream
however i've added return statement inputstream source method. i'm not sure why issue occurring. (the issue began when attempted integrate used publish progress method in current source.)
source:
/* * sends query server , gets parsed results in bundle * urlquerystring - url calling webservice */ protected synchronized inputstream getqueryresults(string urlquerystring) throws ioexception, saxexception, sslexception, sockettimeoutexception, exception { try { // httpsurlconnection https = null; string uri = urlquerystring; list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); basicnamevaluepair mdn1, mdn2,id1,id2; if (mdn.equals("")) { mdn1 = new basicnamevaluepair("mdn1", null); mdn2 = new basicnamevaluepair("mdn2", null); } else { mdn1 = new basicnamevaluepair("mdn1", mdn1.tostring()); mdn2 = new basicnamevaluepair("mdn2", mdn2.tostring()); } basicnamevaluepair car = new basicnamevaluepair("car", car); if (iccid.equals("")) { id1 = new basicnamevaluepair("id1", null); id2 = new basicnamevaluepair("id2", null); } else { id1 = new basicnamevaluepair("id1", id1.tostring()); id2 = new basicnamevaluepair("id2", id2.tostring()); } namevaluepairs.add(mdn1); namevaluepairs.add(mdn2); namevaluepairs.add(car); namevaluepairs.add(id1); namevaluepairs.add(id2); urlencodedformentity urlencodedformentity = new urlencodedformentity( namevaluepairs, "iso-8859-1"); keystore truststore = keystore.getinstance(keystore .getdefaulttype()); truststore.load(null, null); sslsocketfactory sf = new mysslsocketfactory(truststore); sf.sethostnameverifier(sslsocketfactory.allow_all_hostname_verifier); httpparams params = new basichttpparams(); httpprotocolparams.setversion(params, httpversion.http_1_1); httpprotocolparams.setcontentcharset(params, http.utf_8); schemeregistry registry = new schemeregistry(); registry.register(new scheme("http", plainsocketfactory .getsocketfactory(), 80)); registry.register(new scheme("https", sf, 443)); clientconnectionmanager ccm = new threadsafeclientconnmanager( params, registry); httpclient httpclient = new defaulthttpclient(ccm, params); params = httpclient.getparams(); httpclientparams.setredirecting(params, true); httppost httppost = new httppost(uri); httppost.addheader("authorization", getb64auth("nmundru", "abc123")); httppost.setheader("content-type", "text/plain; charset=utf-8"); log.v("httppost", httppost.tostring()); httppost.setentity(urlencodedformentity); httpresponse httpresponse = httpclient.execute(httppost); system.out.println("response...." + httpresponse.tostring()); log.v("response...", httpresponse.tostring()); stream = httpresponse.getentity().getcontent(); // save inputstream in file try { fileoutputstream fout = openfileoutput("settings.xml", context.mode_world_readable); datainputstream in = new datainputstream(stream); bufferedreader br = new bufferedreader( new inputstreamreader(in)); string strline; while ((strline = br.readline()) != null) { system.out.println(strline); //to print response // in logcat fout.write(strline.getbytes()); } fout.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } fis = openfileinput("settings.xml"); } catch (exception e) { log.e(log_tag, e.tostring()); // e.printstacktrace(); tryagain(); } { // https.disconnect(); } publishprogress(r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_empty); try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block } publishprogress(r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full, r.drawable.loading_full); // sleep 1/2 second try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block return stream; } }
currently you're returning stream if final try
block throws interruptedexception
, return statement in catch
block. think meant put return statement 1 brace later - after catch
block. otherwise, end of try/catch statement reachable (because try
block might not throw exception) means can end of method without returning - that's compiler's complaining about.
so instead of this:
protected synchronized inputstream getqueryresults(...) { ... // indentation fixed clarity try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block return stream; } }
you want:
protected synchronized inputstream getqueryresults(...) { ... try { thread.sleep(500); } catch (interruptedexception e) { // todo auto-generated catch block } return stream; }
if had formatted code appropriately - ide happy - you'd have been able see more yourself, suspect.
Comments
Post a Comment