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!
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 trial

Charles Brown
2,135 PointsRibbit app is frustrating ( I think i am done with Treehouse)
I finally finished all three android apps but the one I thought I would be most proud of was the self destructing app, I have studied each video in the course twice before I started the application. So here is my problem after fully completing.
(1. I am able to take picture and videos and send them to a recipient but once it is received in the inbox the picture does not show, its a blank screen for ten seconds and it disappears (as it should) I can not find the reason why it is doing this I have searched through 30 pages in the forum to see if there is an answer (none) (2. When logging out of the application it crashes and freezes my phone(Samsung Galaxy S2/S4) then I get this error message (Unfortunately PicOne has stopped) Logcat doesn't thoroughly explains what could be wrong or point me into the direction of the problem I would love to more with this (i.e create a profile page and adding text messaging) but it seems the basics can not function correctly.
I am hoping someone could help me your time and advice would be greatly appreciated.
Here is the code I am getting form Logcat:
05-30 08:49:01.996: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=641) cached value : gbaSupportIsPossible=false
05-30 08:49:01.996: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=641) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:01.996: I/APACHE HTTP (thCr=641) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=641) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:02.696: I/MainActivity(5687): CB3
05-30 08:49:02.767: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=643) cached value : gbaSupportIsPossible=false
05-30 08:49:02.767: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=643) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:02.767: I/APACHE HTTP (thCr=643) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=643) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:02.807: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=644) cached value : gbaSupportIsPossible=false
05-30 08:49:02.807: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=644) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:02.817: I/APACHE HTTP (thCr=644) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=644) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:02.857: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=645) cached value : gbaSupportIsPossible=false
05-30 08:49:02.857: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=645) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:02.857: I/APACHE HTTP (thCr=645) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=645) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:02.877: I/Adreno200-EGLSUB(5687): <ConfigWindowMatch:2078>: Format RGBA_8888.
05-30 08:49:05.379: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=648) cached value : gbaSupportIsPossible=false
05-30 08:49:05.379: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=648) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:05.379: I/APACHE HTTP (thCr=648) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=648) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:05.439: I/Adreno200-EGLSUB(5687): <ConfigWindowMatch:2078>: Format RGBA_8888.
05-30 08:49:15.469: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=655) cached value : gbaSupportIsPossible=false
05-30 08:49:15.469: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=655) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:15.469: I/APACHE HTTP (thCr=655) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=655) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:15.489: I/Adreno200-EGLSUB(5687): <ConfigWindowMatch:2078>: Format RGBA_8888.
05-30 08:49:15.489: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=656) cached value : gbaSupportIsPossible=false
05-30 08:49:15.489: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(5687): (thUse=656) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
05-30 08:49:15.489: I/APACHE HTTP (thCr=656) - NafRequestExecutorWrapperRedirectionHandler(5687): (thUse=656) It isn't GBA flow, redirection responses are not handled.
05-30 08:49:27.411: I/Adreno200-EGLSUB(5687): <ConfigWindowMatch:2078>: Format RGBA_8888.
05-30 08:49:30.173: I/Adreno200-EGLSUB(5687): <ConfigWindowMatch:2078>: Format RGBA_8888.
05-30 08:49:30.213: W/dalvikvm(5687): threadid=1: thread exiting with uncaught exception (group=0x40bfb1f8)
05-30 08:49:30.223: E/AndroidRuntime(5687): FATAL EXCEPTION: main
05-30 08:49:30.223: E/AndroidRuntime(5687): java.lang.RuntimeException: Unable to resume activity {com.blacsocial.PicOne/com.blacsocial.PicOne.EditFriendsActivity}: java.lang.NullPointerException
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2455)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2483)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1997)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.access$600(ActivityThread.java:127)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.os.Handler.dispatchMessage(Handler.java:99)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.os.Looper.loop(Looper.java:137)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.main(ActivityThread.java:4511)
05-30 08:49:30.223: E/AndroidRuntime(5687): at java.lang.reflect.Method.invokeNative(Native Method)
05-30 08:49:30.223: E/AndroidRuntime(5687): at java.lang.reflect.Method.invoke(Method.java:511)
05-30 08:49:30.223: E/AndroidRuntime(5687): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:976)
05-30 08:49:30.223: E/AndroidRuntime(5687): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
05-30 08:49:30.223: E/AndroidRuntime(5687): at dalvik.system.NativeStart.main(Native Method)
05-30 08:49:30.223: E/AndroidRuntime(5687): Caused by: java.lang.NullPointerException
05-30 08:49:30.223: E/AndroidRuntime(5687): at com.blacsocial.PicOne.EditFriendsActivity.onResume(EditFriendsActivity.java:48)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1157)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.Activity.performResume(Activity.java:4560)
05-30 08:49:30.223: E/AndroidRuntime(5687): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2445)
05-30 08:49:30.223: E/AndroidRuntime(5687): ... 12 more
10 Answers

Ben Jakuben
Treehouse TeacherSorry you're having trouble! Let's take a look at your code to see what might be wrong. The error in logcat does give us an important hint near the bottom:
05-30 08:49:30.223: E/AndroidRuntime(5687): Caused by: java.lang.NullPointerException
05-30 08:49:30.223: E/AndroidRuntime(5687): at com.blacsocial.PicOne.EditFriendsActivity.onResume(EditFriendsActivity.java:48)
Can you paste in your code for EditFriendsActivity.java? Specifically let us know what line 48 is.

Sanat Tripathi
8,109 PointsHi Ben,
I am not facing this issue but performance issue, do you think Ribbit is slow in sending messages (maybe because of image compression) and updating inbox?

Charles Brown
2,135 PointsHello Ben, Thank you for helping me with this issue
here is the code I have for line #48
mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
Thank you I really appreciate your assistance Charles

Ben Jakuben
Treehouse TeacherSanat Tripathi, can you open a new thread to discuss performance? Let's separate these into two separate discussions. This one will focus on Charles' problem.

Ben Jakuben
Treehouse TeacherCharles, can you paste in the rest of your code? One of those key pieces is giving you a null
value. Probably mCurrentUser
. Let's check where mCurrentUser
is set. You can also add a breakpoint at this line and use the debugger to run through your code. When it gets here you can check to see if mCurrentUser
is set or not.
In my code, it is set on the line preceding the one you have shown:
mCurrentUser = ParseUser.getCurrentUser();

Charles Brown
2,135 PointsI totally agree with you, at this point I feel I really frustrated.

Charles Brown
2,135 PointsHello Ben, here is the rest of the code from (EditFriendsActivity,java):
package com.blacsocial.PicOne;
import java.util.List;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseQuery;
import com.parse.ParseRelation;
import com.parse.ParseUser;
import com.parse.SaveCallback;
public class EditFriendsActivity extends ListActivity {
protected ParseRelation<ParseUser> mFriendsRelation;
protected ParseUser mCurrentUser;
public static final String TAG = EditFriendsActivity.class.getSimpleName();
protected List<ParseUser> mUsers;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_edit_friends);
// Show the Up button in the action bar.
setupActionBar();
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
@Override
protected void onResume() {
super.onResume();
mCurrentUser = ParseUser.getCurrentUser();
**mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);**
setProgressBarIndeterminateVisibility(true);
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.orderByAscending(ParseConstants.KEY_USERNAME);
query.setLimit(1000);
query.findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> users, ParseException e) {
setProgressBarIndeterminateVisibility(false);
if (e == null) {
// Success
mUsers = users;
String[] usernames = new String[mUsers.size()];
int i = 0;
for(ParseUser user : mUsers) {
usernames[i] = user.getUsername();
i++;
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
EditFriendsActivity.this,
android.R.layout.simple_list_item_checked,
usernames);
setListAdapter(adapter);
addFriendCheckmarks();
}
else {
Log.e(TAG, e.getMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(EditFriendsActivity.this);
builder.setMessage(e.getMessage())
.setTitle(R.string.error_title)
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
/**
* Set up the {@link android.app.ActionBar}.
*/
private void setupActionBar() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if (getListView().isItemChecked(position)) {
// add the friend
mFriendsRelation.add(mUsers.get(position));
}
else {
// remove the friend
mFriendsRelation.remove(mUsers.get(position));
}
mCurrentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, e.getMessage());
}
}
});
}
private void addFriendCheckmarks() {
mFriendsRelation.getQuery().findInBackground(new FindCallback<ParseUser>() {
@Override
public void done(List<ParseUser> friends, ParseException e) {
if (e == null) {
// list returned - look for a match
for (int i = 0; i < mUsers.size(); i++) {
ParseUser user = mUsers.get(i);
for (ParseUser friend : friends) {
if (friend.getObjectId().equals(user.getObjectId())) {
getListView().setItemChecked(i, true);
}
}
}
}
else {
Log.e(TAG, e.getMessage());
}
}
});
}
}

Ben Jakuben
Treehouse TeacherEverything looks good here, but this code shouldn't be running when you log out. Can you paste your code for the logout button? Perhaps it is taking the user to EditFriendsActivity somehow?
For your other problem with the photo not showing, can you paste your layout code and Activity code for ViewImageActivity?

Charles Brown
2,135 PointsHello Ben sure I can paste those codes here :
package com.blacsocial.PicOne;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;
import com.parse.ParseAnalytics;
import com.parse.ParseUser;
public class MainActivity extends FragmentActivity implements
ActionBar.TabListener {
public static final String TAG = MainActivity.class.getSimpleName();
public static final int TAKE_PHOTO_REQUEST = 0;
public static final int TAKE_VIDEO_REQUEST = 1;
public static final int PICK_PHOTO_REQUEST = 2;
public static final int PICK_VIDEO_REQUEST = 3;
public static final int MEDIA_TYPE_IMAGE = 4;
public static final int MEDIA_TYPE_VIDEO = 5;
public static final int FILE_SIZE_LIMIT = 1024*1024*10; // 10 MB
protected Uri mMediaUri;
protected DialogInterface.OnClickListener mDialogListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which) {
case 0: // Take picture
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
if (mMediaUri == null) {
// display an error
Toast.makeText(MainActivity.this, R.string.error_external_storage,
Toast.LENGTH_LONG).show();
}
else {
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
startActivityForResult(takePhotoIntent, TAKE_PHOTO_REQUEST);
}
break;
case 1: // Take video
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
mMediaUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
if (mMediaUri == null) {
// display an error
Toast.makeText(MainActivity.this, R.string.error_external_storage,
Toast.LENGTH_LONG).show();
}
else {
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, mMediaUri);
videoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
videoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); // 0 = lowest res
startActivityForResult(videoIntent, TAKE_VIDEO_REQUEST);
}
break;
case 2: // Choose picture
Intent choosePhotoIntent = new Intent(Intent.ACTION_GET_CONTENT);
choosePhotoIntent.setType("image/*");
startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
break;
case 3: // Choose video
Intent chooseVideoIntent = new Intent(Intent.ACTION_GET_CONTENT);
chooseVideoIntent.setType("video/*");
Toast.makeText(MainActivity.this, R.string.video_file_size_warning, Toast.LENGTH_LONG).show();
startActivityForResult(chooseVideoIntent, PICK_VIDEO_REQUEST);
break;
}
}
private Uri getOutputMediaFileUri(int mediaType) {
// To be safe, you should check that the SDCard is mounted
// using Environment.getExternalStorageState() before doing this.
if (isExternalStorageAvailable()) {
// get the URI
// 1. Get the external storage directory
String appName = MainActivity.this.getString(R.string.app_name);
File mediaStorageDir = new File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
appName);
// 2. Create our subdirectory
if (! mediaStorageDir.exists()) {
if (! mediaStorageDir.mkdirs()) {
Log.e(TAG, "Failed to create directory.");
return null;
}
}
// 3. Create a file name
// 4. Create the file
File mediaFile;
Date now = new Date();
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(now);
String path = mediaStorageDir.getPath() + File.separator;
if (mediaType == MEDIA_TYPE_IMAGE) {
mediaFile = new File(path + "IMG_" + timestamp + ".jpg");
}
else if (mediaType == MEDIA_TYPE_VIDEO) {
mediaFile = new File(path + "VID_" + timestamp + ".mp4");
}
else {
return null;
}
Log.d(TAG, "File: " + Uri.fromFile(mediaFile));
// 5. Return the file's URI
return Uri.fromFile(mediaFile);
}
else {
return null;
}
}
private boolean isExternalStorageAvailable() {
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
return true;
}
else {
return false;
}
}
};
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.activity_main);
ParseAnalytics.trackAppOpened(getIntent());
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
navigateToLogin();
}
else {
Log.i(TAG, currentUser.getUsername());
}
// Set up the action bar.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(this,
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// When swiping between different sections, select the corresponding
// tab. We can also use ActionBar.Tab#select() to do this if we have
// a reference to the Tab.
mViewPager
.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
// For each of the sections in the app, add a tab to the action bar.
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
// Create a tab with text corresponding to the page title defined by
// the adapter. Also specify this Activity object, which implements
// the TabListener interface, as the callback (listener) for when
// this tab is selected.
actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == PICK_PHOTO_REQUEST || requestCode == PICK_VIDEO_REQUEST) {
if (data == null) {
Toast.makeText(this, getString(R.string.general_error), Toast.LENGTH_LONG).show();
}
else {
mMediaUri = data.getData();
}
Log.i(TAG, "Media URI: " + mMediaUri);
if (requestCode == PICK_VIDEO_REQUEST) {
// make sure the file is less than 10 MB
int fileSize = 0;
InputStream inputStream = null;
try {
inputStream = getContentResolver().openInputStream(mMediaUri);
fileSize = inputStream.available();
}
catch (FileNotFoundException e) {
Toast.makeText(this, R.string.error_opening_file, Toast.LENGTH_LONG).show();
return;
}
catch (IOException e) {
Toast.makeText(this, R.string.error_opening_file, Toast.LENGTH_LONG).show();
return;
}
finally {
try {
inputStream.close();
} catch (IOException e) { /* Intentionally blank */ }
}
if (fileSize >= FILE_SIZE_LIMIT) {
Toast.makeText(this, R.string.error_file_size_too_large, Toast.LENGTH_LONG).show();
return;
}
}
}
else {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(mMediaUri);
sendBroadcast(mediaScanIntent);
}
Intent recipientsIntent = new Intent(this, RecipientsActivity.class);
recipientsIntent.setData(mMediaUri);
String fileType;
if (requestCode == PICK_PHOTO_REQUEST || requestCode == TAKE_PHOTO_REQUEST) {
fileType = ParseConstants.TYPE_IMAGE;
}
else {
fileType = ParseConstants.TYPE_VIDEO;
}
recipientsIntent.putExtra(ParseConstants.KEY_FILE_TYPE, fileType);
startActivity(recipientsIntent);
}
else if (resultCode != RESULT_CANCELED) {
Toast.makeText(this, R.string.general_error, Toast.LENGTH_LONG).show();
}
}
private void navigateToLogin() {
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch(itemId) {
case R.id.action_logout:
ParseUser.logOut();
navigateToLogin();
case R.id.action_edit_friends:
Intent intent = new Intent(this, EditFriendsActivity.class);
startActivity(intent);
case R.id.action_camera:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(R.array.camera_choices, mDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
}
return super.onOptionsItemSelected(item);
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, switch to the corresponding page in
// the ViewPager.
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
}

Ben Jakuben
Treehouse TeacherOkay! You are caught on an error I made myself. You need to add break;
statements at the end of each case in your onOptionsItemSelected()
method:
switch(itemId) {
case R.id.action_logout:
ParseUser.logOut();
navigateToLogin();
break;
case R.id.action_edit_friends:
Intent intent = new Intent(this, EditFriendsActivity.class);
startActivity(intent);
break;
case R.id.action_camera:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setItems(R.array.camera_choices, mDialogListener);
AlertDialog dialog = builder.create();
dialog.show();
break;
}
Without break;
then all the code will run, so after you navigateToLogin()
, you also try to start the EditFriendsActivity. Sorry for the confusion!

Charles Brown
2,135 PointsViewImageActivity
package com.blacsocial.PicOne;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class ViewImageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_image);
// Show the Up button in the action bar.
setupActionBar();
ImageView imageView = (ImageView)findViewById(R.id.imageView);
Uri imageUri = getIntent().getData();
Picasso.with(this).load(imageUri.toString()).into(imageView);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
finish();
}
}, 10*1000);
}
/**
* Set up the {@link android.app.ActionBar}.
*/
private void setupActionBar() {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}

Ben Jakuben
Treehouse TeacherIf you run the debugger and add a breakpoint where you set imageUri
, can you see if it's getting set properly? Perhaps it isn't being attached to the Intent correctly in InboxFragment?

Charles Brown
2,135 PointsHello Ben,
Thank you so kindly for your help I really appreciate it. I have tried using the debugger and adding the breakpoint, but I am unsure of what I am looking for. After adding the break; in the code as you suggested logging out works fine its just sending and receiving the messages continue to freeze m devices

Ben Jakuben
Treehouse TeacherSorry, to clarify: can you send messages? Based on your original question I thought you were just having trouble viewing the images.
No worries about the debugger - using it is an art form! Can you paste in the onListItemClick()
method from your InboxFragment code next? I want to see how you're setting data for the Intent, like this:
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ParseObject message = mMessages.get(position);
String messageType = message.getString(ParseConstants.KEY_FILE_TYPE);
ParseFile file = message.getParseFile(ParseConstants.KEY_FILE);
Uri fileUri = Uri.parse(file.getUrl());
if (messageType.equals(ParseConstants.TYPE_IMAGE)) {
// view the image
Intent intent = new Intent(getActivity(), ViewImageActivity.class);
intent.setData(fileUri);
startActivity(intent);
}
...

Charles Brown
2,135 PointsHello Ben, Yes that is true I can not view the images in the inbox, once the recipient receives and opens it the images does not show. I tried running the debugger but I am not sure what I am looking for. I guess it is my programming skills LOL, here's the code Thanks again for your help.
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
ParseObject message = mMessages.get(position);
String messageType = message.getString(ParseConstants.KEY_FILE_TYPE);
ParseFile file = message.getParseFile(ParseConstants.KEY_FILE);
Uri fileUri = Uri.parse(file.getUrl());
if (messageType.equals(ParseConstants.TYPE_IMAGE)) {
// view the image
Intent intent = new Intent(getActivity(), ViewImageActivity.class);
intent.setData(fileUri);
startActivity(intent);
}
else {
// view the video
Intent intent = new Intent(Intent.ACTION_VIEW, fileUri);
intent.setDataAndType(fileUri, "video/*");
startActivity(intent);
}
//Delete it
List<String> ids = message.getList(ParseConstants.KEY_RECIPIENT_IDS);
if(ids.size() == 1 ){
//last recipient - delete the whole thing
message.deleteInBackground();
}
else{
// remove the recipient and save
ids.remove(ParseUser.getCurrentUser().getObjectId());
ArrayList<String> idsToRemove = new ArrayList<String>();
idsToRemove.add(ParseUser.getCurrentUser().getObjectId());
message.removeAll(ParseConstants.KEY_RECIPIENT_IDS,idsToRemove );
message.saveInBackground();
}
}
}

Ben Jakuben
Treehouse TeacherOkay, let's keep tracing through. We want to make sure that the fileUri
variable has a value when you are attaching it to the Intent. Add the following Log statement to this section of code here and check the URI:
if (messageType.equals(ParseConstants.TYPE_IMAGE)) {
// view the image
Intent intent = new Intent(getActivity(), ViewImageActivity.class);
Log.d("TEST", fileUri.toString()); // ADD THIS LINE
intent.setData(fileUri);
startActivity(intent);
}

Charles Brown
2,135 PointsHello Ben how are you today?
06-16 14:56:31.024: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3421) cached value : gbaSupportIsPossible=false
06-16 14:56:31.024: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3422) cached value : gbaSupportIsPossible=false
06-16 14:56:31.024: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3422) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:31.024: I/APACHE HTTP (thCr=3422) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3422) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:31.034: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3421) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:31.034: I/APACHE HTTP (thCr=3421) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3421) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:31.164: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3423) cached value : gbaSupportIsPossible=false
06-16 14:56:31.164: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3423) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:31.164: I/APACHE HTTP (thCr=3423) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3423) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:31.374: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:56:34.898: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:56:42.005: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3427) cached value : gbaSupportIsPossible=false
06-16 14:56:42.005: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3427) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:42.005: I/APACHE HTTP (thCr=3427) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3427) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:42.045: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3428) cached value : gbaSupportIsPossible=false
06-16 14:56:42.045: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3428) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:42.045: I/APACHE HTTP (thCr=3428) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3428) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:42.065: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:56:42.075: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3429) cached value : gbaSupportIsPossible=false
06-16 14:56:42.075: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3429) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:42.075: I/APACHE HTTP (thCr=3429) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3429) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:42.595: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3431) cached value : gbaSupportIsPossible=false
06-16 14:56:42.595: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3431) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:42.595: I/APACHE HTTP (thCr=3431) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3431) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:45.628: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:56:49.092: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3437) cached value : gbaSupportIsPossible=false
06-16 14:56:49.092: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3437) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:56:49.092: I/APACHE HTTP (thCr=3437) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3437) It isn't GBA flow, redirection responses are not handled.
06-16 14:56:54.647: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:57:20.762: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3438) cached value : gbaSupportIsPossible=false
06-16 14:57:20.772: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3438) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:20.772: I/APACHE HTTP (thCr=3438) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3438) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:21.633: I/MainActivity(18745): CB3
06-16 14:57:21.673: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3440) cached value : gbaSupportIsPossible=false
06-16 14:57:21.673: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3440) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:21.673: I/APACHE HTTP (thCr=3440) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3440) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:21.753: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3441) cached value : gbaSupportIsPossible=false
06-16 14:57:21.753: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3441) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:21.753: I/APACHE HTTP (thCr=3441) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3441) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:21.763: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3442) cached value : gbaSupportIsPossible=false
06-16 14:57:21.763: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3442) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:21.763: I/APACHE HTTP (thCr=3442) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3442) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:21.783: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:57:21.994: W/IInputConnectionWrapper(18745): setComposingText on inactive InputConnection
06-16 14:57:21.994: W/IInputConnectionWrapper(18745): finishComposingText on inactive InputConnection
06-16 14:57:21.994: W/IInputConnectionWrapper(18745): finishComposingText on inactive InputConnection
06-16 14:57:23.675: D/TEST(18745): http://files.parsetfss.com/e01e3bec-63da-4343-aad0-e4a6d7e5bede/tfss-dd5c7bd2-ed88-4429-b898-5052ab58a21a-uploaded_file.png
06-16 14:57:23.725: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3445) cached value : gbaSupportIsPossible=false
06-16 14:57:23.725: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3445) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:23.725: I/APACHE HTTP (thCr=3445) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3445) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:23.805: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:57:33.825: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3452) cached value : gbaSupportIsPossible=false
06-16 14:57:33.825: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3452) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:33.825: I/APACHE HTTP (thCr=3452) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3452) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:33.825: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3453) cached value : gbaSupportIsPossible=false
06-16 14:57:33.825: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3453) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:57:33.825: I/APACHE HTTP (thCr=3453) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3453) It isn't GBA flow, redirection responses are not handled.
06-16 14:57:33.835: I/Adreno200-EGLSUB(18745): <ConfigWindowMatch:2078>: Format RGBA_8888.
06-16 14:58:27.854: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3456) cached value : gbaSupportIsPossible=false
06-16 14:58:27.854: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3456) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:58:27.854: I/APACHE HTTP (thCr=3456) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3456) It isn't GBA flow, redirection responses are not handled.
06-16 14:58:27.874: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3457) cached value : gbaSupportIsPossible=false
06-16 14:58:27.874: I/APACHE HTTP (thCr=1) - NafHttpAuthStrategyDefault(18745): (thUse=3457) It is impossible to support GBA now (many possible reasons: no Android Context, current client is GBA service, etc.), then it will be just usual HTTP.
06-16 14:58:27.874: I/APACHE HTTP (thCr=3457) - NafRequestExecutorWrapperRedirectionHandler(18745): (thUse=3457) It isn't GBA flow, redirection responses are not handled.

Ben Jakuben
Treehouse TeacherSorry for my late reply here. Notice the line that shows that fileUri
is being set correctly:
06-16 14:57:23.675: D/TEST(18745): http://files.parsetfss.com/e01e3bec-63da-4343-aad0-e4a6d7e5bede/tfss-dd5c7bd2-ed88-4429-b898-5052ab58a21a-uploaded_file.png
If you copy that URL and paste it into the browser you can see your test image.
Next you need to see if you can get that same piece of data on the other side, in ViewImageActivity. Add a log statement like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_image);
// Show the Up button in the action bar.
setupActionBar();
ImageView imageView = (ImageView)findViewById(R.id.imageView);
Uri imageUri = getIntent().getData();
Log.d("TEST", imageUri.toString();
...
This should log the same URI to the logcat. If so, then we've further isolated your problem.

Chris Casey
11,656 PointsI was having this same issue and I believe I have narrowed it down to the resolution of the image being sent. It seems Parse was sending the notification but not the actual image. I have tested lowering the resolution of the camera and the image is indeed being displayed in the activity with the lower resolution. I havent checked but maybe Parse has a different size limitation for images than it does for videos. I will do some more testing when I can.

moritz lehnhardt
429 PointsIt was interesting, but then the conversation stopped. :-(
Sanat Tripathi
8,109 PointsSanat Tripathi
8,109 PointsYes man, even I am facing similar issues with Ribbit and did you notice it is super slow? When I send the message it takes around 3-4 secs to actually send it.
Such slow applications can never get to the production level.
Hope someone replies.