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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:25:25+00:00 2026-06-18T08:25:25+00:00

I am tring to get the image width and height in android and load

  • 0

I am tring to get the image width and height in android and load accordingly buy my below code is working fine in 2.3.3 but when i test in higher version(4.0) its height and width are giving null pointer exception…Below is my code…

           Drawable drawable = null; 
           drawable = LoadImageFromWebOperations(logo_url.replace(" ", "%20"));
           System.out.println("Width" + drawable.getMinimumWidth());
           System.out.println("Height" + drawable.getMinimumHeight()); 
           int width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, drawable.getMinimumWidth(), mCtx.getResources().getDisplayMetrics());
           int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, drawable.getMinimumHeight(), mCtx.getResources().getDisplayMetrics());
           client_logo.setMinimumHeight(height);
           client_logo.setMinimumWidth(width);
           client_logo.setImageDrawable(drawable); 


            public Drawable LoadImageFromWebOperations(String url){
System.out.println(url);

    try{
        InputStream is = (InputStream) new URL(url).getContent();
        Drawable d = Drawable.createFromStream(is, "src name");
        return (d);
    }catch (Exception e) {
        //System.out.println("Exc="+e);
        return null;
    }
}
  • 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-18T08:25:27+00:00Added an answer on June 18, 2026 at 8:25 am

    As of API 11, if you are executing this code on the UI thread, the network access will throw a NetworkOnMainThreadException. You don’t post your logcat output (which would be very helpful), but I suspect this is what’s happening. As a result, LoadImageFromWebOperations will return null and you will get a NPE when you try to access the drawable properties.

    You need to run this code in a worker thread. See the article Keeping Your App Responsive.

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

Sidebar

Related Questions

I am trying to get the height and width of an image in windows
I'm trying to get some image processing code working in MS VC++ 2010 express.
I am trying to get an image from URL in Android and set it
I'm trying to get an html5 demo page working on Android 2.1, have tried
For a particular Image say on blue background, I can get its Width and
Look at the picture below. I'm loading an image from sdcard with code belove.
I'm trying to get a webstageview to load a local html file....this code works
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I'm trying to implement an image gallery in android. The code based on http://www.mobisoftinfotech.com/blog/android/android-gallery-widget-example-and-tutorial/
Im trying to get an image from a wcf rest service like so: [ServiceContract]

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.