Hello says in title really. When i click button "Add profile picture" it goes onto gallery as it should but once i click a picrture it collapse and the app closes, why is this? I have an image view that is what is goes on?
CODE FOR ADDING PROFILE PIC IS AT TOP AND BOTTOM OF CODE.
HOPE SOMEONE CAN HELP.
MANY THANKS
package com.example.timetable;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String picturePath = prefs.getString("picture", "");
if(!picturePath.equals("true")){
ImageView imageView = (ImageView) findViewById(R.id.picture);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
{
}
Button buttonLoadImage = (Button) findViewById(R.id.picturebutton);
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});;
Button week1 = (Button) findViewById(R.id.week1button);
Button week2 = (Button) findViewById(R.id.week2button);
Button homework = (Button) findViewById (R.id.homeworkbutton);
//Button Sound
final MediaPlayer buttonSound = MediaPlayer.create(Main.this, R.raw.sound1);
week1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.timetable.WEEK1"));
}});
week2.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.timetable.WEEK2"));
}
});
homework.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
buttonSound.start();
startActivity(new Intent("com.example.timetable.HOMEWORK"));
}});};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private static int RESULT_LOAD_IMAGE = 1;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.picture);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit=shre.edit();
edit.putString("picture", picturePath);
edit.commit();
}}}
CODE FOR ADDING PROFILE PIC IS AT TOP AND BOTTOM OF CODE.
HOPE SOMEONE CAN HELP.
MANY THANKS

Im very new to coding and still cant work out why and its frustrating having a little problem that will ruin your whole app. I hope you understand and i hope you can possibly help me more.