gpt4 book ai didi

java - 网址格式错误异常

转载 作者:行者123 更新时间:2023-12-02 05:29:21 26 4
gpt4 key购买 nike

我收到格式错误的网址异常 http://staging.squadrun.co/media/question_images/2013_Map_Vector_3.jpg

URL url = new URL(src);
HttpURLConnection ucon = (HttpURLConnection) url.openConnection();
ucon.setInstanceFollowRedirects(false);
URL secondUrl = new URL(ucon.getHeaderField("Location"));


HttpURLConnection connection = (HttpURLConnection) secondUrl.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e){
Log.d("sg", "src" + src );
e.printStackTrace();
return null;
}

最佳答案

您在这一行中得到一个 NullpointerException:

URL secondUrl = new URL(ucon.getHeaderField("Location"));

因为ucon.getHeaderField("Location")返回null并且这些NullpointerException被映射到MalformedURLException

Exception in thread "main" java.net.MalformedURLException
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at Test.main(Test.java:16)
Caused by: java.lang.NullPointerException
... 4 more

关于java - 网址格式错误异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25698140/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com