我正在尝试获取图像文件,基本上是用户的个人资料图像。 我已经将图像存储到users表中了 那么这是我的应用
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
navigationItemsList = new ArrayList<DrawerItem>();
addItemsToNavigationList();
mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView);
mRecyclerView.setHasFixedSize(true);
ParseUser userName = ParseUser.getCurrentUser();
HEADER_NAME = userName.getUsername();
HEADER_EMAIL = userName.getEmail();
mAdapter = new com.charity.dogood.dogood.adapters.NavDrawerAdapter(navigationItemsList, this, HEADER_NAME, HEADER_EMAIL, HEADER_IMAGE);
mRecyclerView.setAdapter(mAdapter);
//Parse Image and details of the logged in user
// Locate the class table named "ImageUpload" in Parse.com
ParseQuery<ParseObject> query = new ParseQuery("User");
Log.d("Mainactivity", "After query 1");
ParseUser currentUser = ParseUser.getCurrentUser();
Log.d("Mainactivity", "After query 2");
query.whereEqualTo("username", "bro");
Log.d("Mainactivity", "After query 3");
Log.d("Mainactivity", currentUser.getUsername());
// String usernam = (String)currentUser;
if(currentUser != null){
Log.d("Mainactivity", "came to current user check statement");
query.getInBackground("bro", new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseFile fileObject = (ParseFile) object.getParseFile("ImageProfile");
fileObject.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
Toast.makeText(MainActivity.this, "Welcome Back", Toast.LENGTH_LONG).show();
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
// HEADER_IMAGE image = (ImageView) fin
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.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 {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.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();
}
}
});
Log.d("Mainactivity", "After query 4");
}
我可以在我的抽屉中获取用户名和电子邮件,但不是图像,
对于我放在这里的检查,检查对象null-ivty。
if (e == null) {
我收到此错误消息
答案 0 :(得分:1)
我相信您收到的搜索结果没有找到&#39;因为查询ParseQuery("User")
不会搜索用户类。
尝试更改
ParseQuery<ParseObject> query = new ParseQuery("User")
到
ParseQuery<ParseUser> query = ParseUser.getQuery();
这是根据以下内容查询用户的方式:https://parse.com/docs/android/guide#users-querying
但是,当您只对当前用户感兴趣时,我仍然认为您不需要进行查询:
if(currentUser != null){
Log.d("Mainactivity", "came to current user check statement");
currentUser.fetchIfNeededInBackground(new GetCallback<ParseObject>() {
@Override
public void done(ParseObject object, ParseException e) {
if (e == null) {
ParseFile fileObject = (ParseFile) object.getParseFile("ImageProfile");
fileObject.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] bytes, ParseException e) {
if (e == null) {
Toast.makeText(MainActivity.this, "Welcome Back", Toast.LENGTH_LONG).show();
Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
// HEADER_IMAGE image = (ImageView) fin
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.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 {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.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();
}
}
});