I am able to load image gallery and display image in Imageview. I need to save the image which user selects in parse.com as blackened. Its a picturepath that I am able to load using BitmapFactory. I have created a column in data browser with field as File. I have also gone through the tutorials on Parse.com and implemented each step. But its not working when click on save button. App is crashing each time.
My Code is :
public class LoadImg extends Activity {
private static int RESULT_LOAD_IMAGE = 1;
FrameLayout layout;
Button save ;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
save=(Button) findViewById(R.id.button2);
String picturePath = PreferenceManager.getDefaultSharedPreferences(this).getString("picturePath", "");
if(!picturePath.equals(""))
{
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
Button buttonLoadImage = (Button) findViewById(R.id.button1);
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);
}
});
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Locate the image in res >
Bitmap bitmap = BitmapFactory.decodeFile("picturePath");
// Convert it to byte
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile("picturePath", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a New Class called "ImageUpload" in Parse
ParseObject imgupload = new ParseObject("ImageUpload");
// Create a column named "ImageName" and set the string
imgupload.put("Image", "picturePath");
// Create a column named "ImageFile" and insert the image
imgupload.put("ImageFile", file);
// Create the class and the columns
imgupload.saveInBackground();
// Show a simple toast message
Toast.makeText(LoadImg.this, "Image Uploaded",Toast.LENGTH_SHORT).show();
}
});
}
@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);
PreferenceManager.getDefaultSharedPreferences(this).edit().putString("picturePath", picturePath).commit();
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
}
}}
LogCat is :
01-05 20:43:54.678: E/JavaBinder(1298): !!! FAILED BINDER TRANSACTION !!! 01-05 20:44:48.418: E/AndroidRuntime(3453): Uncaught handler: thread main exiting due to uncaught exception 01-05 20:44:48.428: E/AndroidRuntime(3453): java.lang.NullPointerException 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.lovy.parse.LoadImg$2.onClick(LoadImg.java:56) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.View.performClick(View.java:2418) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.View.onTouchEvent(View.java:4233) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.widget.TextView.onTouchEvent(TextView.java:6645) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.View.dispatchTouchEvent(View.java:3763) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:968) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:968) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:968) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:968) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:968) 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.app.Activity.dispatchTouchEvent(Activity.java:2064) 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.os.Handler.dispatchMessage(Handler.java:99) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.os.Looper.loop(Looper.java:123) 01-05 20:44:48.428: E/AndroidRuntime(3453): at android.app.ActivityThread.main(ActivityThread.java:4370) 01-05 20:44:48.428: E/AndroidRuntime(3453): at java.lang.reflect.Method.invokeNative(Native Method) 01-05 20:44:48.428: E/AndroidRuntime(3453): at java.lang.reflect.Method.invoke(Method.java:521) 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 01-05 20:44:48.428: E/AndroidRuntime(3453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 01-05 20:44:48.428: E/AndroidRuntime(3453): at dalvik.system.NativeStart.main(Native Method) 01-05 20:44:48.438: E/SemcCheckin(3453): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump 01-05 20:44:48.508: E/SemcCheckin(1565): Get Crash Level : java.io.FileNotFoundException: /data/semc-checkin/crashdump 01-05 20:44:58.378: E/ATK(2142): widget kill start