Cannot instantiate the type Uri

All your problems with Audio, Video and Images.

Cannot instantiate the type Uri

Postby daniel37103 » Wed Jun 30, 2010 7:11 pm

I keep getting the error "Cannot instantiate the type Uri" in line 18 of the following code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package org.facedetector2;
  2.  
  3. import java.net.URI;
  4. import java.net.URL;
  5.  
  6. import android.app.Activity;
  7. import android.content.Intent;
  8. import android.net.Uri;
  9. import android.view.KeyEvent;
  10. import static org.facedetector2.Constants.SELECT_IMAGE;
  11.  
  12. public class PhotoChooser extends Activity {
  13.  
  14. public boolean onKeyDown(int keyCode, KeyEvent event) {
  15.         if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER){
  16.                 startActivityForResult(
  17.                         new Intent(Intent.ACTION_PICK,
  18.                         new Uri("android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI")),
  19.                         SELECT_IMAGE);
  20.         return true;
  21.         }
  22. }
  23.        
  24.         @Override
  25.         public void onActivityResult(int requestCode, int resultCode, Intent data) {
  26.           super.onActivityResult(requestCode, resultCode, data);
  27.           if (requestCode == SELECT_IMAGE)
  28.             if (resultCode == Activity.RESULT_OK) {
  29.               Uri selectedImage = data.getData();
  30.               // TODO Do something with the select image URI
  31.             }
  32.         }
  33.  
  34. }
  35.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


Is there any way to fix this error? I have tried making a constructor out of both the Intent and the Uri, but then it gives me "Intent cannot be resolved to a variable" and "Uri cannot be resolved to a variable" errors, respectively.
daniel37103
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jun 30, 2010 7:03 pm

Top

Re: Cannot instantiate the type Uri

Postby padde » Wed Jun 30, 2010 10:01 pm

Uri is an abstract class.. so you cant instantiate it.
This should do what you need:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.     startActivityForResult(
  2.         new Intent(Intent.ACTION_PICK,
  3.         Uri.parse("android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI")),
  4.         SELECT_IMAGE
  5.     );
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
padde
Master Developer
Master Developer
 
Posts: 443
Joined: Wed Apr 08, 2009 4:52 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 16 guests