With the code I am using, the compiler doesn't make it past the first if statement and returns the message "The object was not found ... ". I am trying to download an image from parse.com and place it in an imageView. Attached is my code, the schema for parse class and my XML layout.
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.");
}
}
});
}
}
});
try on this way.
i have change few changes in your existing code like...
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());
}
}
});
In the sending class:
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);
In the receiver's class:
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());
}
}
});
Related
I cannot access the photo that I saved in the User class in parse from android using the code below. If I add a new class to parse and use this exact code, it downloads the picture fine. However, it just won't allow me to pull from the User Class/Table in parse. Why is this and how do I fix it? Do I need to use a pointer? If so, how? Thanks.
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"User");
query.getInBackground("JkANnvy77y",
new GetCallback<ParseObject>() {
public void done(ParseObject object,
ParseException e) {
// TODO Auto-generated method stub
ParseFile fileObject = (ParseFile) object
.get("pictest");
fileObject
.getDataInBackground(new GetDataCallback() {
public void done(byte[] data,
ParseException e) {
if (e == null) {
Log.d("test",
"We've got data in data.");
// Decode the Byte[] into
// Bitmap
Bitmap bmp = BitmapFactory
.decodeByteArray(
data, 0,
data.length);
// Get the ImageView from
// main.xml
ImageView image = (ImageView) findViewById(R.id.ImageView6);
// Set the Bitmap into the
// ImageView
image.setImageBitmap(bmp);
} else {
Log.d("test",
"There was a problem downloading the data.");
}
}
});
}
});
Update: I edited the code to allow me to print the parseexception to logcat and it is telling me that no query was found! GRR
here is my code from another project, adapt it to your needs
//get all images
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<ParseUser>() {
#Override
public void done(List<ParseUser> objects, ParseException e) {
if (objects.size() > 0) {
if (e == null) {
if (!objects.isEmpty()) {
//we have grabbed all the users
//now lets try to get a file
ParseFile file= (ParseUser)objects.get(0).ParseFile("image");
} else if (e.getCode() == ParseException.REQUEST_LIMIT_EXCEEDED) {
makeSnack("Error! Reloading images.");
} else {
e.printStackTrace();
Log.v("error", e.getMessage());
}
} else {
//TODO:// if not images, reregister loclistener
makeSnack("No images located near you.");
}
}
}
});
}
I am trying to upload file to Parse cloud.
final ParseFile parseFile = new ParseFile("somefile.png", data);
parseFile.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null){
ParseObject parseObject = new ParseObject("photo");
parseObject.setObjectId("someId");
parseObject.put("photo1", parseFile);
parseFile.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e==null){
Log.d(TAG, "Save done");
} else {
Log.d(TAG, "ex" + e.getMessage());
}
}
});
} else {
Log.d("USER", "file save ex" + e.getMessage());
}
}
});
This will run and show successfully and show "Save done" log. But when i go to Parse dashboard i don't see anything changing in data.
I tried to retrieve object:
ParseQuery<ParseObject> query = ParseQuery.getQuery("photo");
query.getInBackground("someId", new GetCallback<ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (e == null){
Log.d("USER", "OK");
} else {
Log.d("USER", "ex" + e.getMessage());
}
}
});
But i get ParseException: no results found for query.
Looks like you are saving the parseFile twice and forgetting to save the parse object that you placed the file in.
change this
parseFile.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e==null){
Log.d(TAG, "Save done");
} else {
Log.d(TAG, "ex" + e.getMessage());
}
}
});
to this
parseObject.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e==null){
Log.d(TAG, "Save done");
} else {
Log.d(TAG, "ex" + e.getMessage());
}
}
});
I think that you would to do something like this:
// Create the ParseFile
ParseFile parseFile = new ParseFile("somefile.png", data);
file.saveInBackground();
ParseObject imgupload = new ParseObject("photo");
imgupload.put("ImageName", "somefile");
imgupload.put("photo1", parseFile);
imgupload.saveInBackground();
So, your query:
ParseQuery<ParseObject> query = ParseQuery.getQuery("photo");
query.whereEqualTo("ImageName", "somefile");
query.findInBackground(new FindCallback <ParseObject>() {
#Override
public void done(ParseObject object, ParseException e) {
if (e == null){
Log.d("USER", "OK");
} else {
Log.d("USER", "ex" + e.getMessage());
}
}
});
I have a list of objectId where I am trying to retrieve another list in another class where the pointer value equals the objectId of the current parseObject.
I realised that I am comparing a string "objectId" to a pointer "threadPointer" so can someone help me with the query to retrieve a list of items from a class if the objectId equals the threadPointer _Pointer value
public void retrieveThreadListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.include("postedBy");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
if (!isFinishing()) {
// TODO : Notify to refresh data
}
} else {
Log.d("DEBUG", "ERROR PINNING DATA WITH EXCEPTION : " + e);
}
}
});
}
}
});
}
public void retrievePostsListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Posts");
query.include("postedBy");
query.include("threadPointer");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(final List<ParseObject> list, ParseException e) {
if (e == null) {
// Query is successful now lets load data from parse
ParseObject.pinAllInBackground((List<ParseObject>) list, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
if (!isFinishing()) {
// TODO : Notify to refresh data
Log.d("DEBUG: ","Finished retrieval");
Log.d("DEBUG", list.toString());
ParseObject object = (ParseObject)list.get(1).get("threadPointer");
Log.d("DEBUG_THREAD_POINTER", object.getObjectId());
}
} else {
Log.d("DEBUG", "ERROR PINNING DATA WITH EXCEPTION : " + e);
}
}
});
}
}
});
}
This is where I am retrieving the ThreadList from local db
public void retrieveThreadList(){
List<ParseObject> parseObjectList = new ArrayList<ParseObject>();
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.orderByDescending("updatedAt");
query.fromLocalDatastore();
// Data retrieval was successfull
try {
parseObjectList= query.find();
} catch (ParseException e) {
e.printStackTrace();
}
for (ParseObject parseObject : parseObjectList) {
String title = (String) parseObject.get("threadTitle");
ParseUser parseUser = (ParseUser) parseObject.get("postedBy");
String profilePictureUrl="local";
try {
profilePictureUrl = ((ParseFile) parseUser.get("profilePicture")).getUrl();
}catch (Exception exception)
{
Log.d("DEBUG_FB","profilePicture not retrieved");
}
String threadObjectId = parseObject.getObjectId();
Log.d("DEBUG_FB_THREAD_ID",threadObjectId);
ParseQuery parseQueryToRetrievePosts = ParseQuery.getQuery("Posts");
parseQueryToRetrievePosts.fromLocalDatastore();
//----****** NEED HELP HERE ******----
parseQueryToRetrievePosts.whereEqualTo("threadPointer",parseObject.getObjectId());
try {
List<ParseObject> postsList = parseQueryToRetrievePosts.find();
Log.d("DEBUG_FB_POSTS_LIST",postsList.toString());
} catch (ParseException e) {
e.printStackTrace();
}
/* To retrieve data over the network --- THIS WORKS WELL BUT I DONT WANT A NETWORK CALL
ParseRelation <ParseObject> posts = parseObject.getRelation("postMessage");
ParseQuery postsQuery = posts.getQuery();
List<ParseObject> postsList = new ArrayList();
try {
postsList=postsQuery.find();
for (ParseObject parseObject1: postsList)
{
String postMessage = (String)parseObject1.get("postMessage");
Log.d("DEBUG_FB_MSG", postMessage);
}
Log.d("DEBUG_FB_POSTS", postsList.toString());
}catch (Exception e)
{
}
*/
threadModelStore threadObject = new threadModelStore(title,profilePictureUrl);
Log.d("DEBUG_FB", profilePictureUrl);
Log.d("DEBUG_FB", title);
threadItemList.add(threadObject);
}
Sir my scenario is I have these classes
THREADS(Class) which has POSTS(RELATION TO _POSTS) class I want to retrieve the related posts of a particular thread. I was unable to pin
relations to local data store please let me know if there is a way to
do so ? -- (UNSOLVED)
So what I want to do is to compare the thread pointer in the POSTS
class and retrieve the related posts. For this I needed to compare a
string object id to pointer field _ThreadPointer in POSTS Class
Suggest a possible solution -- SOLVED BY ( VED ).
ParseObject threadPointer=ParseObject.createWithoutData("Pointer_class_Name", "pointer_object_id");
ParseQuery<ParseObject> query=ParseQuery.getQuery("className");
query.whereEqualTo("_Pointer", threadPointer);
query.include("_Pointer");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> listCommunity, ParseException e) {
// TODO Auto-generated method stub
Log.d(TAG, "done");
if(e==null){
// access your data
}else{
// Error in retrieving data
}
I am using parse as BaaS for my android project. Facing duplication of data if I create a custom parse object and saving it as required.
Moreover I tried even extending the parse object to the required class which causes other problems !
public void retrieveThreadListStoreInDB()
{
ParseQuery<ParseObject> query = ParseQuery.getQuery("Threads");
query.include("postedBy");
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
// Data retrieval was successfull
for (ParseObject parseObject : list) {
String title = (String) parseObject.get("threadTitle");
ParseUser parseUser = (ParseUser) parseObject.get("postedBy");
ParseFile userProfilePicture=null;
try
{
userProfilePicture = (ParseFile) parseUser.get("profilePicture");
}
catch (Exception e1)
{
}
String profilePictureUrl=null;
if(userProfilePicture != null) {
profilePictureUrl = (userProfilePicture).getUrl();
}
ParseObject threadsList = new ParseObject("ThreadsList");
threadsList.put("threadTitle",title);
if(profilePictureUrl != null) {
threadsList.put("postedByPicture", profilePictureUrl);
}
else {
threadsList.put("postedByPicture","local");
}
try {
threadsList.pin();
} catch (ParseException e1) {
e1.printStackTrace();
}
Log.d("DEBUG", title);
// Log.d("DEBUG",profilePictureUrl);
}
} else {
Log.d("DEBUG", "Problem with retrieval" + e);
}
}
});
}
HELP ME RESOLVE DUPLICATION OF DATA AND WHAT IS THE BEST WAY TO STORE FILE URL'S, POINTER RELATED INFORMATION AND RELATIONS INFORMATION ?????
i have this code: where i retrieve the courses of a certain student that is loged with the name in "NameCurrentStudent" and then stock the courses in an ArrayList
ParseQuery<ParseObject> query = ParseQuery.getQuery("Courses");
query = query.whereEqualTo("Student", NameCurrentStudent);
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> courseList, ParseException e)
{
if (e == null)
{
courses.clear();
for (ParseObject course : courseList)
{
courses.add(course.getString("NameCourse"));
}
}
else
{
Log.d("Post retrieval", "Error: " + e.getMessage());
}
}
});
but when i use debug it skipps query.findInBackground(new FindCallback() {
anyone know's why ?
ParseQuery<ParseObject> queryP = ParseQuery.getQuery("Courses");
queryP.whereEqualTo("Student", nameStudent);
queryP.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> coursesList, ParseException e)
{
ArrayList<String> courses = null;
if (e == null)
{
courses = new ArrayList<String>();
for (ParseObject course : coursesList)
{
String courseName = course.getString("CoursesNameInParseColumn");
courses.add(courseName);
}
}
else
{
Log.d("Post retrieval", "Error: " + e.getMessage());
}
populateCoursesList(courses);
}
});