使用我正在使用的代码,编译器不会使它超过第一个if语句并返回消息“找不到对象...”。 我正在尝试从parse.com下载图像并将其放在imageView中。附件是我的代码,解析类的架构和我的xml布局。任何帮助将不胜感激。
final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
ParseQuery<ParseObject> query = new ParseQuery<>("Appetizers");
query.addAscendingOrder("appetizer");
query.getInBackground("imageFiles", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, com.parse.ParseException e) {
if (object == null) {
Log.d("test", "The object was not found...");
} else {
Log.d("test", "Retrieved the object.");
final ParseFile fileObject = (ParseFile) object.get("imageFiles");
fileObject.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Log.d("test", "We've got data in data.");
// use data for something
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0,data.length);
mImage.setImageBitmap(bmp);
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});
}
}
});
答案 0 :(得分:0)
尝试这种方式。 我在现有代码中更改了一些更改,例如......
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Appetizers");
query.addAscendingOrder("appetizer");
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
// TODO Auto-generated method stub
if (e == null) {
// success
for (ParseObject parseObject : objects) {
ParseFile fileObject = (ParseFile) parseObject.get("imageFiles");
Log.d("test", "get your image ... " + fileObject.getUrl());
}
} else {
// fail
Log.d("test", "error Message... " + e.getMessage());
}
}
});
答案 1 :(得分:0)
在发送课程中:
ParseObject po = mAppetizers.get(position); // get position
String ID = po.getObjectId().toString();
Intent intent = new Intent(Appetizer.this, AppetizerRecipe.class);
intent.putExtra("ID", ID);
startActivity(intent);
在接收者的课程中:
final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
String ID = getIntent().getStringExtra("ID");
ParseQuery<ParseObject> getimage = new ParseQuery<>("Appetizers");
getimage.addAscendingOrder("appetizer");
getimage.whereEqualTo("ID", ID);
Log.d("AppetizerRecipe2", "object: " + ID);
getimage.getInBackground(ID, new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
Log.v("what is e?", "e = " + e);
// success
final ParseFile fileObject = (ParseFile)object.get("imageFiles");
fileObject.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
Log.d("test", "We've got data in data.");
// use data for something
Log.d("test", "Get your image..." + fileObject.getUrl());
Picasso.with(getBaseContext()).load(fileObject.getUrl()).placeholder
(R.drawable.ic_launcher).into(mImage);
} else {
Log.d("test", "There was a problem downloading the data.");
}
}
});
} else {
// fail
Log.d("test", "Error Message..." + e.getMessage());
}
}
});