Android 缓存位图时没有这样的文件或目录?

Android 缓存位图时没有这样的文件或目录?,android,Android,我一直在犯这个错误 07-28 19:32:40.536: ERROR/error(534): java.io.IOException: No such file or directory 07-28 19:32:40.536: ERROR/error(534): at java.io.File.createNewFileImpl(Native Method) 07-28 19:32:40.536: ERROR/error(534): at java.io.File.create

我一直在犯这个错误

07-28 19:32:40.536: ERROR/error(534): java.io.IOException: No such file or directory
07-28 19:32:40.536: ERROR/error(534):     at java.io.File.createNewFileImpl(Native Method)
07-28 19:32:40.536: ERROR/error(534):     at java.io.File.createNewFile(File.java:1115)
07-28 19:32:40.536: ERROR/error(534):     at com.fttech.gameIT.MainMenu.putBitmapInDiskCache(MainMenu.java:447)
这是我的putBitmapInDiskCache()

编辑:成功了!现在我明白了

07-28 19:56:31.525: ERROR/DEBUGTAG(573): java.io.FileNotFoundException: /881625833 (No such file or directory)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
  07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:239)
07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.<init>(FileInputStream.java:88)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.<init>(FileInputStream.java:122)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at com.fttech.gameIT.MainMenu$ImageAdapter.getView(MainMenu.java:297)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.makeAndAddView(Gallery.java:748)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.fillToGalleryLeft(Gallery.java:667)

您缺少一个
cacheDir.mkdirs()
调用。这样做,然后执行
File cacheFile…

它应该是这样的:File cacheDir=new File(this.getCacheDir(),“缩略图”);cacheDir.mkdirs();File cacheFile=新文件(cacheDir,“+imageUri.hashCode());当一个人被刷到视野之外时,图像就会消失。您正在“thumbnails”文件夹中逐个创建一个文件,但尝试从根目录而不是缩略图中读取。您需要了解更多有关编程的信息:)String cachFile=this.getCacheDir()+“/thumbnails/”+imageUri.hashCode();成功了!!!我知道。我是爪哇的一名高中生,在加拿大和C++度过了第二年。所以我还是很了解android,但很快就适应了。当涉及到像你们这样的非常复杂的代码时,就不是很好了。你是怎么康复的?顺便说一句,如果图像发生变化会发生什么?意思是它们不是相同的图像?缓存最终会被填满吗?
07-28 19:56:31.525: ERROR/DEBUGTAG(573): java.io.FileNotFoundException: /881625833 (No such file or directory)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
  07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:239)
07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.<init>(FileInputStream.java:88)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at java.io.FileInputStream.<init>(FileInputStream.java:122)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at com.fttech.gameIT.MainMenu$ImageAdapter.getView(MainMenu.java:297)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.makeAndAddView(Gallery.java:748)
 07-28 19:56:31.525: ERROR/DEBUGTAG(573):     at android.widget.Gallery.fillToGalleryLeft(Gallery.java:667)
try {


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



                                URI imageUri = null;
                                try {
                                    imageUri = aURL.toURI();
                                } catch (URISyntaxException e1) {
                                    // TODO Auto-generated catch block
                                    e1.printStackTrace();
                                }
                                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;
                                            }