0

I have recieved the below error while trying to run my application: FATAL EXCEPTION, and OutOfMemoryError error, and have included the log cat message below:

10-16 11:40:09.819: E/AndroidRuntime(668): FATAL EXCEPTION: Task.BACKGROUND_EXECUTOR-thread-13
10-16 11:40:09.819: E/AndroidRuntime(668): java.lang.OutOfMemoryError
10-16 11:40:09.819: E/AndroidRuntime(668):  at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
10-16 11:40:09.819: E/AndroidRuntime(668):  at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseIOUtils.copyLarge(ParseIOUtils.java:130)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseIOUtils.copyLarge(ParseIOUtils.java:106)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseIOUtils.copy(ParseIOUtils.java:81)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseIOUtils.toByteArray(ParseIOUtils.java:55)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseFileUtils.readFileToByteArray(ParseFileUtils.java:47)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseFile.getCachedData(ParseFile.java:188)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseFile.access$500(ParseFile.java:24)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseFile$6.then(ParseFile.java:507)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.ParseFile$6.then(ParseFile.java:504)
10-16 11:40:09.819: E/AndroidRuntime(668):  at com.parse.Task$10.run(Task.java:448)
10-16 11:40:09.819: E/AndroidRuntime(668):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
10-16 11:40:09.819: E/AndroidRuntime(668):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
10-16 11:40:09.819: E/AndroidRuntime(668):  at java.lang.Thread.run(Thread.java:856)

This occured when the below activity opened:

public class matchOptionActivity1 extends Activity{

    protected TextView mUserRetrieved;
       private String currentUserId;

       protected TextView mUserActivityNameRetrieved;
       protected TextView mUserNameRetrieved;
       protected TextView mUserAgeRetrieved;
       protected TextView mUserHeadlineRetrieved;
       String userGender = ParseUser.getCurrentUser().getString("Gender");
       String activityName = ParseUser.getCurrentUser().getString("ActivityName");
       Number maxDistance = ParseUser.getCurrentUser().getNumber(
               "Maximum_Distance");
       String userLookingGender = ParseUser.getCurrentUser().getString(
               "Looking_Gender");
       Number minimumAge = ParseUser.getCurrentUser().getNumber("Minimum_Age");
       Number maximumAge = ParseUser.getCurrentUser().getNumber("Maximum_Age");
       Number userage = ParseUser.getCurrentUser().getNumber("UserAge");
       private FeedbackDialog feedBack;
       private ProgressDialog progressDialog;
       private BroadcastReceiver receiver;
       private MessageService.MessageServiceInterface sinchService;
       private Boolean bound = false;





  @Override
  public void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      setContentView(R.layout.matchoption);


   feedBack = new FeedbackDialog(this, "AF-46D8F2A319EA-0A");
      ParseQuery<ParseUser> query = ParseUser.getQuery();

      // query.whereEqualTo("ActivityName",userActivitySelectionName);

      query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
              .getObjectId());
      // users with Gender = currentUser.Looking_Gender
      query.whereEqualTo("Gender", userLookingGender);
      // users with Looking_Gender = currentUser.Gender
      query.whereEqualTo("Looking_Gender", userGender);
      query.setLimit(1);
      //  query2.whereEqualTo("UserMatchedRequest1", "confirmed");
      query.whereEqualTo("ActivityName", activityName);
      query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
      query.whereLessThanOrEqualTo("UserAge", maximumAge);

      ParseQuery<ParseUser> query2 = ParseUser.getQuery();

      // query.whereEqualTo("ActivityName",userActivitySelectionName);

      query2.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
              .getObjectId());
      // users with Gender = currentUser.Looking_Gender
      query2.whereEqualTo("Gender", userLookingGender);
      // users with Looking_Gender = currentUser.Gender
      query2.whereEqualTo("Looking_Gender", userGender);
      query2.setLimit(1);
      //  query2.whereEqualTo("UserMatchedRequest1", "confirmed");
      query2.whereEqualTo("ActivityName", activityName);
      query2.whereGreaterThanOrEqualTo("UserAge", minimumAge);
      query2.whereLessThanOrEqualTo("UserAge", maximumAge);

      query.findInBackground(new FindCallback<ParseUser>() {
          @Override
          public void done(List<ParseUser> objects,ParseException e) {

              for(int i=0;i<objects.size();i++){
                  // Do whatever you need to extract object from "users"
                  ParseQuery<ParseObject> query = ParseQuery.getQuery("User");
                  query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                          .getObjectId());
                  // users with Gender = currentUser.Looking_Gender
                  query.whereEqualTo("Gender", userLookingGender);
                  // users with Looking_Gender = currentUser.Gender
                  query.whereEqualTo("Looking_Gender", userGender);
                  query.setLimit(1);
                  //  query2.whereEqualTo("UserMatchedRequest1", "confirmed");

                  query.whereEqualTo("ActivityName", activityName);
                  query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
                  query.whereLessThanOrEqualTo("UserAge", maximumAge);

                  mUserNameRetrieved = (TextView) findViewById(R.id.tvmname1);

                  mUserNameRetrieved.setText(objects.get(i).get("Name").toString()); 



              }
  }//for loop
          });

      query2.findInBackground(new FindCallback<ParseUser>() {

          @Override
          public void done(List<ParseUser> objects,ParseException e) {

              for(int i=0;i<objects.size();i++){
                  // Do whatever you need to extract object from "users"
                     ParseQuery<ParseObject> query2 = ParseQuery.getQuery("User");
                     query2.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                             .getObjectId());
                     // users with Gender = currentUser.Looking_Gender
                     query2.whereEqualTo("Gender", userLookingGender);
                     // users with Looking_Gender = currentUser.Gender
                     query2.whereEqualTo("Looking_Gender", userGender);
                     query2.setLimit(1);
                   //  query2.whereEqualTo("UserMatchedRequest1", "confirmed");

                     query2.whereEqualTo("ActivityName", activityName);
                     query2.whereGreaterThanOrEqualTo("UserAge", minimumAge);
                     query2.whereLessThanOrEqualTo("UserAge", maximumAge);


                  ParseFile image = objects.get(i).getParseFile("ProfilePicture");


                  ParseImageView imageView = (ParseImageView) findViewById(R.id.profilePictureresultm);



                   // The placeholder will be used before and during the fetch, to be replaced by the fetched image
                   // data.
                   imageView.setPlaceholder(getResources().getDrawable(R.drawable.profile_pict));
                   imageView.setParseFile(image);

                   imageView.loadInBackground(new GetDataCallback() {
                     @Override
                     public void done(byte[] data, ParseException e) {
                         if (data != null) {
                             Log.i("ParseImageView", "Fetched: " + data.length);
                           } else {
                             Log.e("ParseImageView", "Error fetching: " + e.getMessage());
                           }
                     }


               });
              }
  }//for loop
          });




      final Button ichat = (Button) this.findViewById(R.id.btnQuickChat);
       ichat.setOnClickListener(new OnClickListener() {

           @Override
           public void onClick(View v) {


          openConversation();


           }


           private void openConversation() {
               // TODO Auto-generated method stub
                 ParseQuery<ParseUser> query = ParseUser.getQuery();
                    query.whereNotEqualTo("objectId", ParseUser.getCurrentUser()
                          .getObjectId());
                       // users with Gender = currentUser.Looking_Gender
                        query.whereEqualTo("Gender", userLookingGender);
                        // users with Looking_Gender = currentUser.Gender
                         query.whereEqualTo("Looking_Gender", userGender);
                        query.setLimit(1);
                       query.whereEqualTo("ActivityName", activityName);
                       query.whereGreaterThanOrEqualTo("UserAge", minimumAge);
                        query.whereLessThanOrEqualTo("UserAge", maximumAge);


                   query.findInBackground(new FindCallback<ParseUser>() {
                       public void done(List<ParseUser> user, ParseException e) {
                             if (e == null) {

                                  Intent intent = new Intent(getApplicationContext(), MessagingActivity1.class);
                                  Intent serviceIntent = new Intent(getApplicationContext(), MessageService.class); 
                                  startService(serviceIntent);

                                  intent.putExtra("RECIPIENT_ID", user.get(0).getObjectId());
                                  startActivity(intent);
                              } else {
                                  Toast.makeText(getApplicationContext(),
                                      "Error finding that user",
                                          Toast.LENGTH_SHORT).show();
                              }
                          }
                       });
                   }
       });


}


    // show a loading spinner while the sinch client starts
    private void showSpinner() {
        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("Loading");
        progressDialog.setMessage("Please wait...");
        progressDialog.show();
        receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                Boolean success = intent.getBooleanExtra("success", false);
                progressDialog.dismiss();
                if (!success) {
                    Toast.makeText(getApplicationContext(),
                            "Messaging service failed to start",
                            Toast.LENGTH_LONG).show();
                }
            }
        };
        LocalBroadcastManager.getInstance(this).registerReceiver(
                receiver,
                new IntentFilter(
                        "com.dooba.beta.MatchOptionActivity1"));
    }

    @Override
    public void onResume() {
        super.onResume();
    }
}

Any help would be greatly appreciated

4
  • 1
    you are loading a file that cannot fit in your allotted heap size Commented Oct 16, 2014 at 18:48
  • how would I be able to overcome that? Commented Oct 16, 2014 at 18:51
  • 1
    with Parse you cant, it forces you to load the entire file into memory. You can try using the REST-API to get a file so you can stream it and get small chunks at a time Commented Oct 16, 2014 at 18:56
  • use a thumbnail or scale down your profile pic. Your bitmap and reqmts for memory are too large so reduce the memory impact of your process on profile photo. Commented Oct 16, 2014 at 23:25

1 Answer 1

1

Well, your exception occurs on separate thread and we can't see the faulty place directly in your code.
Still, it definitely happens during parse.

Let me suppose that the processed file is too big.
So try to comment out line imageView.setParseFile(image) or try with another image file.
When you find the place causing the error you should decide whether:
- you have to limit the size of the images
- convert images to reduce their size
- use some other approach with parsing

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.