2

I have a button:

final Button dialogButtonFotoPerfil1 = (Button) dialogFotosPerfil .findViewById(R.id.botonFotoPerfil1); dialogButtonFotoPerfil1.setOnClickListener(new MediaGaleryActivity()); 

which I want to show an image picker. MediaGaleryActivity.java is:

import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.provider.MediaStore; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.ImageView; import com.gayworld.R; import com.gayworld.utils.Utilidades; public class MediaGaleryActivity extends Activity implements OnClickListener { private static final int SELECT_IMAGE = 1; private static String TAG; @Override public void onClick(View v) { TAG = "MediaGaleryActivity.onClick"; Log.d(TAG, "Inicio."); Intent intent = null; switch (v.getId()) { case R.id.botonFotoPerfil1: intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); Log.d(TAG, "Error valor gallery "+intent.toString()); startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE); break; default: break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); TAG = "MediaGaleryActivity.onActivityResult"; Log.d(TAG, "Inicio."); if(resultCode==RESULT_OK && requestCode==SELECT_IMAGE){ Uri selectedImage=data.getData(); String path=getPath(selectedImage); Bitmap bitmapImage=BitmapFactory.decodeFile(path); ImageView image=(ImageView)findViewById(R.id.image); image.setImageBitmap(bitmapImage); } } public String getPath(Uri uri){ TAG = "MediaGaleryActivity.getPath"; Log.d(TAG, "Inicio."); String[] filePathColumn={MediaStore.Images.Media.DATA}; Cursor cursor=getContentResolver().query(uri, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex=cursor.getColumnIndex(filePathColumn[0]); return cursor.getString(columnIndex); } } 

But I´m getting a NullPointerException.

Logcat:

05-25 13:52:15.287: D/MediaGaleryActivity.onClick(11620): Inicio. 05-25 13:52:15.295: D/MediaGaleryActivity.onClick(11620): Error valor gallery Intent { act=android.intent.action.GET_CONTENT typ=image/* } 05-25 13:52:15.295: D/AndroidRuntime(11620): Shutting down VM 05-25 13:52:15.295: W/dalvikvm(11620): threadid=1: thread exiting with uncaught exception (group=0x40a2c1f8) 05-25 13:52:15.334: E/AndroidRuntime(11620): FATAL EXCEPTION: main 05-25 13:52:15.334: E/AndroidRuntime(11620): java.lang.NullPointerException 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.app.Activity.startActivityForResult(Activity.java:3190) 05-25 13:52:15.334: E/AndroidRuntime(11620): at com.gayworld.screen.activity.MediaGaleryActivity.onClick(MediaGaleryActivity.java:34) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.view.View.performClick(View.java:3511) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.view.View$PerformClick.run(View.java:14105) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.os.Handler.handleCallback(Handler.java:605) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.os.Handler.dispatchMessage(Handler.java:92) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.os.Looper.loop(Looper.java:137) 05-25 13:52:15.334: E/AndroidRuntime(11620): at android.app.ActivityThread.main(ActivityThread.java:4575) 05-25 13:52:15.334: E/AndroidRuntime(11620): at java.lang.reflect.Method.invokeNative(Native Method) 05-25 13:52:15.334: E/AndroidRuntime(11620): at java.lang.reflect.Method.invoke(Method.java:511) 05-25 13:52:15.334: E/AndroidRuntime(11620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 05-25 13:52:15.334: E/AndroidRuntime(11620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) 05-25 13:52:15.334: E/AndroidRuntime(11620): at dalvik.system.NativeStart.main(Native Method) 

I get this error and I don´t know what I can do more. I have been reading a lot of blogs, answers,.. I also ask for google help... but nothing. I always get the same error. Any idea?? Because I´m really stuck with it.

Thanks in advance.

1
  • 2
    in your Logcat, few lines more below there should be something like Caused by. Which line is it indicating? Commented May 25, 2013 at 12:01

1 Answer 1

0

Are you sure your MediaGalleryActivity has context?

Check this out, the user was doing something similar and getting a NPE on startActivity -> https://stackoverflow.com/a/16748203/2114852

Other than that, you'd have to provide the full logcat as the comment suggests.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.