2011-07-28 18 views
3

このコードを使用してこれらの画像をキャッシュしようとしています...URLをURIに変換するには?

ここで構文エラーが発生しますか?

Uri imageUri = new Uri(aURL); 

ここではコードを使用しています。

       URL aURL = new URL(myRemoteImages[position]); 



           Uri imageUri = new Uri(aURL); 
           if (new File(new File(myContext.getCacheDir(), "thumbnails"), "" + imageUri.hashCode()).exists()) 
           { 
            String cachFile = ""+imageUri.hashCode(); 
            FileInputStream fis; 

            try { 
             fis = new FileInputStream(cachFile); 
             Bitmap bm = BitmapFactory.decodeStream(fis); 
             i.setImageBitmap(bm); 
              i.setScaleType(ImageView.ScaleType.FIT_CENTER); 
              /* Set the Width/Height of the ImageView. */ 
              if(Build.VERSION.SDK_INT >= 11){ 
               i.setLayoutParams(new Gallery.LayoutParams(450, 300)); 
              } 
              else{ 
               i.setLayoutParams(new Gallery.LayoutParams(125, 125)); 
              } 


            } catch (FileNotFoundException e) { 

              Log.e("DEBUGTAG", "Remtoe Image Exception", e); 





              /* Image should be scaled as width/height are set. */ 
              i.setScaleType(ImageView.ScaleType.FIT_CENTER); 
              /* Set the Width/Height of the ImageView. */ 
              if(Build.VERSION.SDK_INT >= 11){ 
               i.setLayoutParams(new Gallery.LayoutParams(450, 300)); 

              return i; 
              } 
               i.setLayoutParams(new Gallery.LayoutParams(125, 125)); 
               return i; 
              } 
http://developer.android.com/reference/java/net/URL.html#toURI
+0

すべてのURLがされているURIをしようと、すべてではないURIはURLです。 URIは、例えば相対パスとすることができる。 URLが有効な場合(java.net.URLオブジェクトがある場合)、以下のようにniekとして行うことができます。 –

+0

ありがとう、私はそれをimageUri = aUrl.toUri();とwalla –

+0

btw ..あなたは私の質問をお願いします投票してください。 –

答えて

4

docs. URLを使用してURIを作成することはできません。

URI uri = new URI(aURL.toString()); 

のようなものを使用してください。

+1

URI!=ウリ。そのコンストラクタは存在しません。 – Simian

+0

タイプミスを許します.. – nhaarman

0

()

この方法を参照してください。あなたには役に立ちます

関連する問題