Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMasum Bergmann
Courses Plus Student 4,129 PointsRetrieving (Text)File from Parse.com using getDataInBackground() does not work!
Hi all!
I'm working on the Ribbit project and have implemented a text sending and receiving feature. To retrieve the text file I have used the following code:
file.getDataInBackground(new GetDataCallback() {
@Override
public void done(byte[] data, ParseException e) {
if (e == null)
{
mTextMsg = new String(data);
}
else
{
Log.e("InboxFrag","e: " + e);
}
}
});
However this does not return anything into mTextMsg. I have used the debug mode and found out that after this code runs, mTextMsg remains null. Why is that? Am I doing something wrong? My guess would be yes, but I can't see what.
I have then tried the "not so recommended" way of calling getData() instead:
try {
mTextMsg = new String(file.getData());
} catch (ParseException e) {
Log.e("InboxFrag","e: " + e);
}
This actually works, but the downside is that data retrieval is not done in the Background.
I have no idea why the getDataInBackground() method does not work! (SOOOOO FRUSTRATING!!) Any help figuring this out would be very much appreciated... Thanks!!
1 Answer
Ben Jakuben
Treehouse TeacherWith the first method, what do the data
and e
variables hold when you step into the done()
method?
Masum Bergmann
Courses Plus Student 4,129 PointsMasum Bergmann
Courses Plus Student 4,129 PointsHi Ben, sorry for the delayed response, but I was on holiday in Spain with rather limited access to the internet!
data
actually contains the text information and looks like :72, 101, 108, 108, 111
which I'm guessing is ok sincedata
is a byte array.e
is null, which I suppose is also good news!Does this mean that there may be a problem converting the byte array into a string?
Thanks for your help!!
Ben Jakuben
Treehouse TeacherBen Jakuben
Treehouse TeacherHmmm...I'm not sure why your
data
isn't being converted. Perhaps it has something to do with how the array is being stored: http://stackoverflow.com/a/6684822/475217However, I'm wondering if it would be easier and more efficient to store the text message as simply a new text column rather than putting it into a file.
Masum Bergmann
Courses Plus Student 4,129 PointsMasum Bergmann
Courses Plus Student 4,129 PointsCheers Ben, I'll keep playing around with it a bit more and will let you know if I find anything!