Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:46:15+00:00 2026-06-11T18:46:15+00:00

I have been having a LOT of memory issues with my app. I’m trying

  • 0

I have been having a LOT of memory issues with my app. I’m trying to catch the memory exceptions and then display a message using toast saying out of memory.

When I run the app with the tast code it crashes. When I run it in the debugger, does not crash but no message comes up.

I’m trying to display the message within the catch memory exception inside the onCreate method of the Activty class.

code block:

public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);


            // set size of card image
            ImageView CardImage = ( ImageView)findViewById(R.id.viewcard);
            int ScreenWidth=getWindowManager().getDefaultDisplay().getWidth();
            int ScreenHeight=getWindowManager().getDefaultDisplay().getHeight();

            // fix for tblets
            if (ScreenHeight<ScreenWidth)
               ScreenWidth=ScreenHeight;

            int CardWidth=ScreenWidth/2;
            CardWidth+=CardWidth/10;

            // set bitmap
        //    Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.card2);
            String FileName=new String("card");
            FileName+=Integer.toString( CardId+1);
            FileName+=".jpg";


            // put in text that matches card
            TextView mCardText = (TextView)findViewById(R.id.cardtext);
            mCardText.setText( "Card Meaning \n"+ cCardText.mCardMeaning[ CardId]);

            // put in text that matches card
            TextView mHouseText = (TextView)findViewById(R.id.housetext);
            mHouseText.setText( "House Meaning \n"+ cCardText.mHouseMeaning[ HouseId-1]);

        try {
       AssetManager assetManager= getAssets();
       InputStream inputStream;
       inputStream=assetManager.open(FileName);  
       Bitmap icon=BitmapFactory.decodeStream(inputStream);
       CardImage.setImageBitmap(icon);
        } catch( OutOfMemoryError e)
        {
    /////////////////////////////////////////////////////////////////////
    // crashes heare
            Context context = getApplicationContext();
            CharSequence text = "Out of Memory  ";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();  

            gi++;
              return;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return;
        } 


        //scale it
        // note: only code here that pertains to card image, becouse if card image cannot be loaded
        // the above exceptions will go off and we will never get here
        CardImage.getLayoutParams().width=CardWidth;
        CardImage.getLayoutParams().height = (int)( (float) CardWidth *1.7);


    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:46:16+00:00Added an answer on June 11, 2026 at 6:46 pm

    When you are OutOfMemory, all bets are pretty much off because at that point the JVM cannot really allocate any new memory. So it’s likely crashing due to that reason.

    You might want to try clearing out some pointers before displaying the message… but I’ve never seen anyone actually try to catch an OutOfMemory error.

    The 3rd answer down here in this post Is it possible to catch out of memory exception in java? explains a bit why its a really bad idea to try to catch outofmemory exceptions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a lot of trouble using an external JAR, GPars, in
I have been trying to build a basic search script. Having a lot of
I've been having a lot of trouble trying to get our app moved from
Lately we been having a lot of problems with our mysql server i have
I have been having this annoying problem when trying to implement a picture gallery
I have been having some trouble with matplotlib since I started using python. When
I'm having a lot of issues with trying to perform some core data operations
I have been having lot of problems with users uploading images on my website.
I have been having a lot of trouble getting cocotron to create a simple
I am having a lot of fun with Linq2Sql. Expression Trees have been great,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.