Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
上传照片到解析(android)_Android_Image_Parse Platform - Fatal编程技术网

上传照片到解析(android)

上传照片到解析(android),android,image,parse-platform,Android,Image,Parse Platform,我是parse.com的新用户,我想将用户选择的图像上传到parse.com 用户选择图像,然后选择图像的名称,然后按上载按钮 但当我单击“上载”按钮时,程序崩溃:( 这是我的尝试 Button btn; ImageView Pic; ParseObject shop; final int PHOTO_SELECTED = 1; ParseFile file; ParseFile photoFile; final Context contex

我是parse.com的新用户,我想将用户选择的图像上传到parse.com

用户选择图像,然后选择图像的名称,然后按上载按钮

但当我单击“上载”按钮时,程序崩溃:(

这是我的尝试

   Button btn;
    ImageView Pic;
    ParseObject shop;
    final int PHOTO_SELECTED = 1;
    ParseFile file;
    ParseFile photoFile;
    final Context context = this;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.openshop);  

        btn = (Button) findViewById(R.id.button1);
        Pic = (ImageView) findViewById(R.id.imageView1);
        final int PHOTO_SELECTED = 1;


        Pic.setOnClickListener(new View.OnClickListener() {
            public void onClick(View arg0) {

                Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);    
                startActivityForResult(i,PHOTO_SELECTED); 

            }
        });

    } 

    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         super.onActivityResult(requestCode, resultCode, data);

         if (requestCode == PHOTO_SELECTED && 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]);
             final String picturePath = cursor.getString(columnIndex);
             cursor.close();

            final Bitmap bitmap = BitmapFactory.decodeFile(picturePath);
             Pic.setImageBitmap(bitmap);


             btn.setOnClickListener(new View.OnClickListener() {
                @SuppressLint("NewApi")
                public void onClick(View arg0) {
                     EditText name = (EditText) findViewById(R.id.sname);

                    shop = new ParseObject("imagetest");

                     // Bitmap bitmap =BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), Pic);

                        // 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(name.getText().toString()+".png", image);

                        // Upload the image into Parse Cloud
                        file.saveInBackground();


                        //Create
                        shop.put("name", name.getText().toString());
                        shop.put("UserOpen",ParseUser.getCurrentUser());
                        shop.put("Image", file);

                        shop.saveInBackground();


                        // Show a simple toast message
                        Toast.makeText(getApplicationContext(), "Created",
                                Toast.LENGTH_SHORT).show();
                }

             });

         }
    }

}

谢谢你也发布日志猫。你能发布日志吗?在这里查看我的日志。希望有帮助。