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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:47:03+00:00 2026-06-06T07:47:03+00:00

I am prepared code for download images from server and store in sdcard.For that

  • 0

I am prepared code for download images from server and store in sdcard.For that i have prepared code,

 URL url;
 try {
     url = new URL("http://myserver_path/applikaza/appstore/apks/ScrResoluton/scrresolution.jpg");
     input = url.openStream();
     String storagePath = Environment.getExternalStorageDirectory().toString();
     String basepath = storagePath + "/Guayama/" + folderName;
     output = new FileOutputStream(basepath + "/home.png");
     byte[] buffer = new byte[5000];

     int bytesRead = 0;
     while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
         output.write(buffer, 0, bytesRead);
     }

 } catch (MalformedURLException e) { // TODO Auto-generated catch block
     e.printStackTrace();
 } finally {
     output.close();
     input.close();
 }   

but got NullPointerException at output.close().I think done mistake some where .please help me.

  • 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-06T07:47:06+00:00Added an answer on June 6, 2026 at 7:47 am

    The reason you get a NullPointerException at output.close() is because your URL is incorrectly formed. For starters, it doesn’t contain a valid protocol. This will cause MalformedURLException to be thrown on the line

    url = new URL("E:/Suresh/images/home.png");
    

    and you’ll then go straight to the catch block, followed by the finally block which calls output.close(), but output is null since the line

    output = new FileOutputStream(basepath + "/home.png");
    

    was never executed.

    You need to correct your URL (see the description here) and you need to correct your exception handling, as in the case of MalformedURLException, this will only ever be thrown where you set the value of url, and so you will never have a non-null value for output or input when your “finally” block is executed.

    Your URL should probably be of the form “http://something/Suresh/images/home.png” or maybe “file://something/Suresh/images/home.png”. If the home.png file is located on another machine to the Android device, try and access it via a web browser and use the URL shown by the web browser complete with “http://”.

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

Sidebar

Related Questions

I have an inner class that downloads some images from the server. The problem
I have a prepared statement: PreparedStatement st; and at my code i try to
I'm using AFNetworking to pull images from a URL, resize, store to disk and
I have prepared a code to just play a simple mp4 file from my
In my application i need to open pdf file.For that i have prepared code
I have my application designed with Repository pattern implemented and my code prepared for
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt
I prepared a WLST script that prints all sever names from WebLogic cluster to
We have a Prepared Statement in Java and we hear that it is different
I have this code NSString *tr = [self sendUrl:@http://google.com/]; But for some reason '

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.