Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 试图在android中检索位图时抛出filenotfoundexception的fileinputstream_Java_Android_Eclipse - Fatal编程技术网

Java 试图在android中检索位图时抛出filenotfoundexception的fileinputstream

Java 试图在android中检索位图时抛出filenotfoundexception的fileinputstream,java,android,eclipse,Java,Android,Eclipse,我正在尝试从内存中检索位图,但它在旧版本上工作,而在新版本的android上不工作。它引发filenotfoundexception 我使用的代码是: public Bitmap getImageBitmap(Context context,String name){ //BufferedInputStream bis = null; FileInputStream fis=null; try{ // FileInputStrea

我正在尝试从内存中检索位图,但它在旧版本上工作,而在新版本的android上不工作。它引发filenotfoundexception

我使用的代码是:

public Bitmap getImageBitmap(Context context,String name){
        //BufferedInputStream bis = null;
        FileInputStream fis=null;
        try{
//          FileInputStream fis = context.openFileInput(name);
//            File file = new File("filesdir", name);
              File myFile = new File (path_file+File.separator+name); 
            //byte [] mybytearray  = new byte [(int)myFile.length()];
            fis = new FileInputStream(myFile);
             //bis = new BufferedInputStream(fis);
                Bitmap b = BitmapFactory.decodeStream(fis);
                //fis.close();
                return b;
            }
            catch(Exception e){
                return null;
            }
          finally{
              if(fis!=null)
              {
                try {
                    fis.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
              }

          }

        }

fileinputstream对象
fis
抛出filenotfoundexception。请帮助

好的,你评论了
BufferedInputStream
像这样使用它

File myFile = new File ( path+ File.separator + fname); 
                byte [] mybytearray  = new byte [(int)myFile.length()];
                FileInputStream fis = new FileInputStream(myFile);
                BufferedInputStream bis = new BufferedInputStream(fis);
                bis.read(mybytearray,0,mybytearray.length);

根据您的程序更改变量名

您为
fis
提供的路径示例可能会有所帮助。路径可能未正确格式化,这导致了异常。(另外,检查文件是否确实存在,但我假设您已经这样做了。)什么是
path\u文件
?什么是
名称
?为什么要使用字符串连接而不是相应的
文件
构造函数?使用
FileNotFoundException
失败的完整路径是什么?为什么你捕捉到异常e,然后什么也不做?上面的代码在旧的android 2.6上运行良好,但在新的androdi 4+上失败。我将该方法称为Bitmap obj=getImageBitmap(MainActivity.this,s.category+“.png”);path_file=MainActivity.this.getFilesDir().getAbsolutePath();path_filepath_file=MainActivity.this.getFilesDir().getAbsolutePath()的值是多少;为什么它在旧设备上运行良好。但在新设备上失败?close方法如何?什么close方法??如果您正在谈论fis.close();比我建议你删除最后块