How can I solve this error "java.net.MalformedURLException: protocol not found:" in android

im getting error for java.net.MalformedURLException: Protocol not found: in android. How can I solve this problem, I try for a long time, but do not get a solution. plz help me

 05-24 12:22:48.885: WARN/System.err(1358): java.net.MalformedURLException: Protocol not found: 05-24 12:22:48.905: WARN/System.err(1358): at java.net.URL.<init>(URL.java:273) 05-24 12:22:48.935: WARN/System.err(1358): at java.net.URL.<init>(URL.java:157) 05-24 12:22:48.935: WARN/System.err(1358): at com.bestdambikers.Updates$EfficientAdapter$4.onClick(Updates.java:354) 05-24 12:22:48.935: WARN/System.err(1358): at android.view.View.performClick(View.java:2485) 05-24 12:22:48.935: WARN/System.err(1358): at android.view.View$PerformClick.run(View.java:9080) 05-24 12:22:48.965: WARN/System.err(1358): at android.os.Handler.handleCallback(Handler.java:587) 05-24 12:22:48.965: WARN/System.err(1358): at android.os.Handler.dispatchMessage(Handler.java:92) 05-24 12:22:48.965: WARN/System.err(1358): at android.os.Looper.loop(Looper.java:123) 05-24 12:22:48.975: WARN/System.err(1358): at android.app.ActivityThread.main(ActivityThread.java:3647) 05-24 12:22:48.985: WARN/System.err(1358): at java.lang.reflect.Method.invokeNative(Native Method) 05-24 12:22:48.985: WARN/System.err(1358): at java.lang.reflect.Method.invoke(Method.java:507) 05-24 12:22:48.985: WARN/System.err(1358): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 05-24 12:22:48.995: WARN/System.err(1358): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-24 12:22:49.025: WARN/System.err(1358): at dalvik.system.NativeStart.main(Native Method) 

this is the code where i get the error ...

 strUrl = "http://192.168.5.156/html/maykal/maykalvirtue/index.php?option=com_ijoomer&plg_name=jomsocial&pview=user&ptask=activities&sessionid="+ ConstantData.session_id + ""; parser = new XmlParser(strUrl, new UpdatesBean()); result = parser.ParseUrl("data", "update"); UpdatesBean updatesBean = (UpdatesBean) result.get(position); ConstantData.pos = position; Log.e("POSITION OF CLICKED ROW",""+ConstantData.pos); URL newurl = new URL(updatesBean.thumb); //getting error at this line bi = BitmapFactory.decodeStream(newurl.openConnection().getInputStream()); ConstantData.updateImage = bi; ConstantData.titleTag = updatesBean.titletag; ConstantData.updateDate = updatesBean.date; 
+4
source share
2 answers

He does not raise an exception, he complains that you have failed in what he can, although he wonโ€™t, because the URL in this case is not distorted. (The Java designers thought this concept, โ€œchecked exceptions,โ€ was a good idea, although it didnโ€™t work well in practice.)

To close it, add MalformedURLException throws or its superclass will throw an IOException in the method declaration. For instance:

 public void myMethod() throws IOException { URL url = new URL("https://wikipedia.org/"); } 

Alternatively, catch and reconstruct the annoying exception as an uncontrolled exception

 public void myMethod() { try { URL url = new URL("https://wikipedia.org/"); ... } catch (IOException e) { throw new RuntimeException(e); } } 
+1
source

updatesBean.thumb invalid URL. In particular, he does not have a valid protocol. This is a message. It is not in your code where this updateBean.thumb comes from. But, based on the name, it is possible that this is more a URI than a URL. Print and see what it is. And, since it is large, it is probably a file. Can I suggest you use something like this to determine the real file name?

  public String getRealPathFromURI(Uri contentUri) { if (contentUri.toString().startsWith("file://")) { return contentUri.toString(); } String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, // Which columns to // return null, // WHERE clause; which rows to return (all rows) null, // WHERE clause selection arguments (none) null); // Order-by clause (ascending by name) int column_index = cursor .getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return "file://" + cursor.getString(column_index); } 
0
source

All Articles