2013-05-13 46 views
1

在我的数据库中,我有每个条目一个uri到我的手机上的图片。要在手机上显示它,Listview有一个CustomAdapter。现在,我想显示在ListView的图片,并得到以下错误消息:无法解码流:FileNotFoundException

05-13 12:20:34.234: E/BitmapFactory(17684): Unable to decode stream: java.io.FileNotFoundException: /external/images/media/10139: open failed: ENOENT (No such file or directory) 
BitmapDrawable: cannot decode external/images/media/10139 

它发生在这个功能:

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    ViewHolderEreignis holder; 

    if(convertView == null){ 
     convertView = inflator.inflate(R.layout.list_ereignis, parent, false); 
     holder = new ViewHolderEreignis((TextView) convertView.findViewById(R.id.enullline), (TextView) convertView.findViewById(R.id.efirstLine), (ImageView) convertView.findViewById(R.id.eimgv)); 

     convertView.setTag(holder); 
    } 
    else{ 
     holder = (ViewHolderEreignis) convertView.getTag(); 
    } 

    Ereignis ki = (Ereignis) getItem(position); 
    holder.getEreignisname().setText(ki.getEreignisname()); 
    holder.getEreignisdatum().setText(ki.getEreignisZeit()); 
    Uri uri = Uri.parse(ki.getEreignisbild()); 
    BitmapDrawable b = new BitmapDrawable(ki.getEreignisbild()); 

    System.out.println("ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ" + uri.getPath()); 
    holder.getEreignisbild().setImageDrawable(b); 

    return convertView; 

} 

就像你看到的,我输出的图像中的URI看起来像这样:

external/images/media/10139 

有人知道这个错误吗?

编辑: 这里是代码,我添加图像:

ContentValues values = new ContentValues(); 
    String TITLE = null; 
    values.put(MediaStore.Images.Media.TITLE, TITLE); 
    String DESCRIPTION = null; 
    values.put(MediaStore.Images.Media.DESCRIPTION, DESCRIPTION); 
    values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg"); 
    imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); 
    System.out.println("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVvv" + imageUri.getPath()); 
    startActivityForResult(intent, IMAGE_CAPTURE); 

EDIT2:

这里是我的链接添加到数据库的代码:

public void insertereignis(String ename, String ezeit, String egenaueres, String ebild, int kindid){ 
     long rowId = -1; 
     try{  
      SQLiteDatabase db = getWritableDatabase(); 


      ContentValues cv = new ContentValues(); 
      System.out.println(ename + ezeit + egenaueres); 
      cv.put(EREIGNISNAME, ename); 
      cv.put(EREIGNISZEIT, ezeit); 
      cv.put(EREIGNISGENAUERES, egenaueres); 
      cv.put(EREIGNISBILD, ebild); 
      System.out.println("GRIAISDALSDJLASJDLKASJDKLAJSDLKJFS" + ebild); 
      cv.put(KINDID, kindid); 

      rowId = db.insert(TABLE_NAME_EREIGNIS, null, cv);   
     } 
     catch (SQLiteException e){ 
      Log.e(TAG, "insert() Ereignis", e); 
     } 
     finally{ 
      Log.d(TAG, "insert(): Ereignis rowId=" + rowId); 
     } 
    } 

ebild的值是/external/images/media/10146

+0

你不需要文件扩展名?像'10139.jpg'什么的? – nikmin 2013-05-13 10:46:43

+0

我试过,但没有,我不需要它 – user896692 2013-05-13 10:53:26

+0

然后我认为它是与图像路径的东西。它清楚地表明没有这样的文件。你的形象在哪里? – nikmin 2013-05-13 11:03:55

回答

0

难道你没有看到问题吗?你有很多解决方案。

  1. 变化ebild有格式/DCIM/Camera/filename.jpg值,然后使用imgeUri这样的:

    imageUri = Environment.getExternalStorageDirectory().getAbsolutePath() + uri.toString(); 
    
  2. 变化ebild有格式filename.jpg值,然后使用imgeUri这样的:

    imageUri = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/" + uri.toString(); 
    
  3. 指定整个图像路径为ebild,如:

    ebild = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/" + "filename.jpg" 
    

    然后用它作为图像uri而不做任何修改。

我不知道还能说什么。解决方案很明显。

编辑:

这里是你如何设置文件名时间戳:

Calendar c = Calendar.getInstance(); 
String cameraImageFileName = "IMG_" + c.get(Calendar.YEAR) + "-" + 
       ((c.get(Calendar.MONTH)+1 < 10) ? ("0" + (c.get(Calendar.MONTH)+1)) : (c.get(Calendar.MONTH)+1)) + "-" + 
       ((c.get(Calendar.DAY_OF_MONTH) < 10) ? ("0" + c.get(Calendar.DAY_OF_MONTH)) : c.get(Calendar.DAY_OF_MONTH)) + "_" + 
       ((c.get(Calendar.HOUR_OF_DAY) < 10) ? ("0" + c.get(Calendar.HOUR_OF_DAY)) : c.get(Calendar.HOUR_OF_DAY)) + "-" + 
       ((c.get(Calendar.MINUTE) < 10) ? ("0" + c.get(Calendar.MINUTE)) : c.get(Calendar.MINUTE)) + "-" + 
       ((c.get(Calendar.SECOND) < 10) ? ("0" + c.get(Calendar.SECOND)) : c.get(Calendar.SECOND)) + ".jpg"; 

你会得到的文件名格式IMG_YYYY-MM-DD_HH-MM-SS.jpg

和你imageUri是:

imageUri = Environment.getExternalStorageDirectory().getAbsolutePath() + cameraImageFileName; 

,你应该将其添加为ebild在数据库:

insertereignis(为ename,ezeit,egenaueres,imageUri,kindid);

+0

不,必须有一个不同的问题。我添加了一个硬编码的文件路径,它也没有显示出来! – user896692 2013-05-13 13:45:15

+0

你添加了什么编码路径?你在哪里添加它?试试这个:'BitmapDrawable b = new BitmapDrawable(Environment.getExternalStorageDirectory()。getAbsolutePath()+“/ DCIM/Camera /”+“filename.jpg”);'其中filename.jpg是某个现有图像的名称 – nikmin 2013-05-13 13:49:28

+0

我加了这个:/storage/emulated/0/DCIM/Camera/1368438768752.jpg – user896692 2013-05-13 14:12:44