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 7959473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:34:45+00:00 2026-06-04T04:34:45+00:00

I’m building a real simple Android app and a lot is going wrong. I

  • 0

I’m building a real simple Android app and a lot is going wrong.

I can’t even get a decent Try Catch Everything running. And since the machine I got is hugely underpowered I’m testing directly on my android device but that’s not really working.

The application seems to crash after doing a basic action even using a generic try catch. What am I doing wrong here.

Why is the try catch not catching anything?

This is my Main.xml (a textview and another control are snipped out)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

 <ImageButton
        android:id="@+id/ib"
        android:layout_width="300dip"
        android:layout_height="50dip"
        android:text="Hello World, MyActivity"
        android:scaleType="fitXY"
        android:onClick="onButtonClicked"
        />

This is my simple code (and the Image isn’t even showing)

public void onButtonClicked(View v) {
    try {
        String strFilePath = "/mnt/sdcard/somefile.jpg";
        if (strFilePath.length() > 0) {

            File file = new File(strFilePath);

            if (file.exists()) {
                ShowToast(strFilePath + "Bestaat");

                ImageButton image = (ImageButton) findViewById(R.id.ib);
                Bitmap bMap = BitmapFactory.decodeFile(strFilePath);
                image.setImageBitmap(bMap);

                ShowToast( "Done");
            } else {
                ShowToast(strFilePath + "Bestaat NIET");
            }
        } else {
            ShowToast(strFilePath + "strFilePath.length() =0");
        }

    } catch (Exception e) {
        HandleError(e);
    }
}

Solution

The files where over 3Mb in size. The ImageButton won’t show pictures that ‘big’ and simply do nothing.
The application probably threw some random out of memory exceptions loading the images taking down the entire app.

Reading a logcat was enough to debug this ‘problem’

Some code that does work (kindly borrowed from other SO questions)

    ImageButton image = (ImageButton) findViewById(R.id.ib);

    Bitmap bMap = BitmapFactory.decodeFile(strFilePath);
    Bitmap bSized = getResizedBitmap(bMap,150,150);
    image.setImageBitmap(bSized);

And

    public Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth)                     
    {
      int width = bm.getWidth();
      int height = bm.getHeight();
      float scaleWidth = ((float) newWidth) / width;
      float scaleHeight = ((float) newHeight) / height;

      // create a matrix for the manipulation
      Matrix matrix = new Matrix();

      // resize the bit map
      matrix.postScale(scaleWidth, scaleHeight);

      // recreate the new Bitmap
      Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
      return resizedBitmap;

}
  • 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-04T04:34:46+00:00Added an answer on June 4, 2026 at 4:34 am

    Either you don’t have an ImageButton with that id, or the image you are trying to load is to big to fit in the reduced application memory.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I am writing an app with both english and french support. The app requests

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.