2012-04-18 12 views
1

ネットワークドライブからImageViewビットマップを設定します。しかし、私はUnableがサーバーに接続するようになっている:サーバー(PASS)にログインできません:141.11.11.247エラー。ここでURLからのImageView

は、このために私のダウンロードアリsetBitmapコードです:

public class ResimCek implements Runnable {

int resimID = 0; 

    public ResimCek(int parcaID) { 
     // store parameter for later user 
     resimID = parcaID; 
    } 

    public void run() { 
     try { 
      ImageView resim = (ImageView) findViewById(resimID); 
      Bitmap bitmap = BitmapFactory 
        .decodeStream((InputStream) new URL(
          "file://141.11.11.247/foto_metod/Parca/" 
            + Integer.toString(resimID) + ".jpg") 
          .getContent()); 
      resim.setImageBitmap(bitmap); 
     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
} 

ここに私の最後のコードは次のとおりです。あなたの助けのための

public class ResimCek implements Runnable {

int resimID = 0; 

    public ResimCek(int parcaID) { 
     // store parameter for later user 
     resimID = parcaID; 
    } 

    public void run() { 

     int resID = getResources().getIdentifier(Integer.toString(resimID) , "tag", getPackageName()); 
     ImageView resim = (ImageView) findViewById(resID); 

     Drawable image = ImageOperations(getBaseContext(),"http://141.11.11.206/parca/" + Integer.toString(resimID) + ".jpg" ,"I" + Integer.toString(resimID) + ".jpg"); 
     // ****************************************************** 
     resim.setImageDrawable(image); // I GOT THE ERROR HERE!!! 
    } 
} 
private Drawable ImageOperations(Context ctx, String url, String saveFilename) { 
    try { 
     InputStream is = (InputStream) this.fetch(url); 
     Drawable d = Drawable.createFromStream(new URL(url).openConnection().getInputStream(),saveFilename); 
     return d; 
    } catch (MalformedURLException e) { 
     e.printStackTrace(); 
     return null; 
    } catch (IOException e) { 
     e.printStackTrace(); 
     return null; 
    } 
} 

public Object fetch(String address) throws MalformedURLException,IOException { 
    URL url = new URL(address); 
    Object content = url.getContent(); 
    return content; 
} 

感謝。

答えて

1

あなたのマニフェストファイルでインターネット権限を宣言するのを忘れた場合は、ご確認ください。

+0

私は

+1

を見つけました。コード内のプロトコルはhttp/httpsの代わりにファイルです。画像を転送するためにどのようなプロトコルを使用しますか? – mariotaku

+0

と、ネットワークドライブにログインする必要がありますか? – mariotaku

0

FtpClient

をダウンロードし、ログインするためのユーザー名とパスワードを使用します。 thisのドキュメントをご覧ください。

+0

私の画像はネットワークドライブに保存されており、Webサーバーではありません。だから私はファイルプロトコルを使用する –

+0

私の編集したコードを使用して、それがあなたを助けてくれることを願っています。 –

+0

Suvamさんからの返信ありがとうございますが、私はそれがファイルにアクセスするためのftpまたはhttpプロトコルではないと言います。それは単なるネットワークマシンであり、サーバーではありません。 –