开发者

how can i solve this error " java.net.MalformedURLException: Protocol not found: " in android

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$MethodAndArgsC开发者_高级运维aller.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;


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);
    }
}


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜