Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Android app closes after choosing picture, why?
icon3.gif  Android app closes after choosing picture, why? [message #1280605] Sun, 30 March 2014 16:33 Go to next message
Lewis Watson is currently offline Lewis WatsonFriend
Messages: 1
Registered: March 2014
Junior Member
Hello i have made an app and i have a button that chooses your profil picture from you gallaery. when i click on it, it loads gallary and i choose a picture, but whne i do the app i made force closes. How can it work? Please help.
Many thanks
Here is code in main.java:
FIRST PART AT START AND SECOND PART AT END.

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("profilepic", "");
if(!picturePath.equals("true")){
ImageView imageView = (ImageView) findViewById(R.id.ProfileImage);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
{
}

Button buttonLoadImage = (Button) findViewById(R.id.profilebutton);
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.ProfileImage);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));

SharedPreferences shre = PreferenceManager.getDefaultSharedPreferences(this);
Editor edit=shre.edit();
edit.putString("profilepic", picturePath);
edit.commit();


}}}




Re: Android app closes after choosing picture, why? [message #1281155 is a reply to message #1280605] Mon, 31 March 2014 12:48 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
See http://www.eclipse.org/forums/index.php/t/225513/ (always appears at the top of this forum so I don't know how you could miss it).
Previous Topic:want to learn about making android apps
Next Topic:TFS Work Item Tracking Copy/Paste Greyed Out in OSX
Goto Forum:
  


Current Time: Fri Apr 26 12:38:30 GMT 2024

Powered by FUDForum. Page generated in 0.07412 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top