setImageURI() Problem

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

setImageURI() Problem

Postby rgrandy » Sat Nov 28, 2009 6:20 am

This is a pretty basic thing but I couldn't get it to work in a more complex routine so I tried to reduce it to the simplest possible thing and it still won't work and it is driving me up a wall!

I am trying to set an image on an ImageView using the function setImageURI(), the program compiles however the ImageView is blank and never gets set. And in the logcat it gives the error:

11-27 22:23:51.405: INFO/System.out(18614): resolveUri failed on bad bitmap uri: file:///sdcard/icon.png

However I know this is a good URI because I can get the gallery to show the image using and intent with the URI.

What am I missing??


images.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public class images extends Activity {
  3.  
  4.        
  5.  
  6.         private ImageView iv;
  7.  
  8.        
  9.  
  10.     /** Called when the activity is first created. */
  11.  
  12.     @Override
  13.  
  14.     public void onCreate(Bundle savedInstanceState) {
  15.  
  16.         super.onCreate(savedInstanceState);
  17.  
  18.         setContentView(R.layout.main);
  19.  
  20.  
  21.  
  22.         // make file reference
  23.  
  24.                 File file = new File("/sdcard/icon.png");
  25.  
  26.                 Log.d("here", "Does this exist? " + String.valueOf(file.exists()));
  27.  
  28.                
  29.  
  30.                 // create uri for file
  31.  
  32.                 Uri uri = Uri.fromFile(file);
  33.  
  34.                
  35.  
  36.                 //reference the imageview
  37.  
  38.                 iv = (ImageView) findViewById(R.id.photo);
  39.  
  40.                 iv.setImageURI(uri);
  41.  
  42.                
  43.  
  44.                 Log.d("here",uri.getPath());
  45.  
  46.                
  47.  
  48.                 // call an android image viewer
  49.  
  50. //              Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
  51.  
  52. //              intent.setDataAndType(uri, "image/png");
  53.  
  54. //              startActivity(intent);
  55.  
  56.                
  57.  
  58.     }    
  59.  
  60. }
  61.  
  62.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


main.xml - layout
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5.  
  6.     android:orientation="vertical"
  7.  
  8.     android:layout_width="fill_parent"
  9.  
  10.     android:layout_height="fill_parent"
  11.  
  12.     >
  13.  
  14.         <ImageView
  15.  
  16.                 android:layout_width="wrap_content"
  17.  
  18.         android:layout_height="wrap_content"
  19.  
  20.         android:id="@+id/photo"
  21.  
  22.     />
  23.  
  24. </LinearLayout>
  25.  
  26.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
Attachments
log.txt
logcat output
(6.63 KiB) Downloaded 44 times
rgrandy
Freshman
Freshman
 
Posts: 3
Joined: Sun Nov 22, 2009 11:24 pm

Top

Postby padde » Sat Nov 28, 2009 8:05 am

If i remember right the setimageuri method of the imageview do not accept
all kinds of URIs. I use it with content URIs from my own content provider and
thats working fine. But you could try variations like "file://path/to/file.jpg" or
something like that.
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Majestic-12 [Bot], Yahoo [Bot] and 8 guests