我正在尝试在用户注册期间将配置文件图像存储到Parse。 当我尝试将图像文件与用户一起存储时,我收到错误。 这是代码,
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("check", "ckpoint signup 2");
Parse.initialize(this, "NOA", "NOA");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
//initialize
mUsername = (EditText)findViewById(R.id.usernameRegisterEditText);
mUserEmail = (EditText)findViewById(R.id.emailRegisterEditText);
mUserPassword = (EditText)findViewById(R.id.passwordRegisterEditText);
mRegisterButton =(Button)findViewById(R.id.registerButton);
mPictureButton = (ImageButton)findViewById(R.id.pictureImageButton);
mPictureButton.setOnClickListener(cameraListener);
final ImageView imageView = (ImageView)findViewById(R.id.pictureImageButton);
//Register Button listener
Log.d("check", "ckpoint 2");
mRegisterButton.setOnClickListener(new View.OnClickListener() {
//Log.d("check", "ckpoint 2");
@Override
public void onClick(View view) {
Log.d("check", "ckpoint signup click register 100");
final String username = mUsername.getText().toString().trim();
final String password = mUserPassword.getText().toString().trim();
final String email = mUserEmail.getText().toString().trim();
//Parse picture
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
// 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
final ParseFile file = new ParseFile("Profile.png", image);
// Upload the image into Parse Cloud
file.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
builder.setMessage(e.getMessage());
builder.setTitle("Sorry");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
else
{
Toast.makeText(Register.this, "Sucessfully saved", Toast.LENGTH_LONG).show();
}
}
},
new ProgressCallback() {
@Override
public void done(Integer integer) {
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password);
user.setEmail(email);
user.put("ImageProfile",file);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if (e == null) {
Toast.makeText(Register.this, "Sucessfully signed up", Toast.LENGTH_LONG).show();
//take user home
Intent takeUserHome = new Intent(Register.this, Login.class);
startActivity(takeUserHome);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
builder.setMessage(e.getMessage());
builder.setTitle("Sorry");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show(); }}});}}); }; });}
但是我说错了 无法编码未保存的解析文件,我知道已经存在问题,但我想知道的是如何确保首先上传文件然后继续执行后续步骤?我也不能同时做这一切吗?这是API的编写方式吗?
答案 0 :(得分:0)
将整个user.signUpInBackground代码移动到file.saveInBackground中:从ProgressCallback完成:完成....