0
リモートサーバーから画像をダウンロードします。しかし、私はnullpointer例外を得るたびに。ビットマップAndroidリモート画像ERROR
private Bitmap DownloadImage(String URL)
{
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
Log.i("Download ", "InputStream Available: " +in.available());
bitmap = BitmapFactory.decodeStream(in);
Log.i("Download ", "Bitmap: " +bitmap.describeContents());
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
私はdecodeStreamときヌルpointerExceptionがスローされ
が、私は別のURLを使用する場合、それが動作を作成するためのサーバーへのConenctingについては
方法
private InputStream OpenHttpConnection(String urlString)
throws IOException
{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
Log.i("Download ", "Response: OK");
}
else
Log.i("Download ", "Response: NOK");
}
catch (Exception ex)
{
throw new IOException("Error connecting");
}
return in;
}
方法。
私はポート90でApacheを実行します。これが有効な場合は、これも有効ですか?
@Simsファイルの使用をダウンロードするには、このコード
を使用し、FTPに接続する
はそのコードあなたと罰金仕事やないですか? – Nik88
あまりにも長い時間をかけて申し訳ありませんが、私は問題を理解しました。これはJPEG画像ではなくPNG画像をアップロードするときに機能します。しかし、私はあなたのコードを使用してアップロードします。 – Sims
答えがあなたに役立つ場合は@Sims回答の左側にある右矢印をチェックすることができます。 – Nik88