4

i m getting error for java.net.MalformedURLException: Protocol not found: in android. How can i solve this i am trying from long time but not getting 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 m getting 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;
7
  • 1
    Please add code from com.bestdambikers.Updates$EfficientAdapter$4.onClick method (thats the method that located in URL.java file and contains line 157). Commented May 24, 2011 at 7:10
  • I don't see where you use strUrl is your code... Commented May 24, 2011 at 7:29
  • 1
    Your error comes from the value of updatesBean.thumb. You should check that value and see what's wrong with it Commented May 24, 2011 at 7:31
  • 1
    i have edited...now u can find whr i m using strUrl Commented May 24, 2011 at 9:47
  • What is updatesBean.thumb ? Is it a valid URL? Commented May 24, 2011 at 9:50

2 Answers 2

1

It is not raising the exception, it's complaining that you haven't handled the possibility that it might, even though it won't, because the URL in this case is not malformed. (Java's designers thought this concept, "checked exceptions", was a good idea, although in practice it hasn't worked well.)

To shut it up, add throws MalformedURLException, or its superclass throws IOException, to the method declaration. For example:

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

Alternatively, catch and rethrow the annoying exception as an unchecked exception

public void myMethod() {
    try {
        URL url = new URL("https://wikipedia.org/");
        ...
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

updatesBean.thumb is not valid URL. In particular - it doesn't have valid protocol. That's what message is about. It's not in your code where this updatesBean.thumb come from. But, based on name, it's possible that it rather URI and not URL. Print and see what it is. And, since it's thumb it is, probably, a file. May I suggest you use something like this to determine 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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.