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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:59:46+00:00 2026-06-14T14:59:46+00:00

I published an app where I need to copy a few hunderd kb size

  • 0

I published an app where I need to copy a few hunderd kb size ogg file onto the sdcard of the user. Soon I got an error report. As far as I am concerned the problem might be because the path is not suitable on that specific phone:

String path = "/sdcard/file.ogg"; 

            File file = new File(Environment.getExternalStorageDirectory(), "file.ogg" );
            if (!file.exists()) {


                InputStream in = getResources().openRawResource(R.raw.file);
                FileOutputStream out = null;
                try {
                    out = new FileOutputStream(path);
                } catch (FileNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                byte[] buff = new byte[1024];
                int read = 0;

                try {
                    while ((read = in.read(buff)) > 0) {
                        out.write(buff, 0, read);
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } finally {
                    try {
                        in.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    try {
                        out.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

So the report is:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.caodeveloping.androgangnam/com.caodeveloping.androgangnam.Main}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
at android.app.ActivityThread.access$1500(ActivityThread.java:121)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.caodeveloping.androgangnam.Main.onCreate(Main.java:388)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
... 11 more

And the 388th row is the out.close(); Is it possible that /sdcard/ is not suitable path on that phone? What could cause this? Thanks in advance!

Update, this?

String path= Environment.getExternalStorageDirectory().getAbsolutePath();
path += "/file.ogg";
  • 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-14T14:59:47+00:00Added an answer on June 14, 2026 at 2:59 pm

    Two problems:

    a) Obviously, you are trying to close file (out.close()), event if you wasn’t able to open it

    b) I would recommend to use Environment.getExternalStorageDirectory(), instead of hardcoded directory name “/sdcard”. It’s not guaranteed that SD card will be mounted to this path. That’s exactly the reason of Environment.getExternalStorageDirectory() API.

    Also, I recommend to review this whole code for error handling (if something can’t be opened, read, etc.)

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

Sidebar

Related Questions

I'am getting sometimes the following error on my published web app with ELMAH: System.Web.HttpException
For specific customer requirement, I need to allow the user of my app (
I've had an app published on Google Play for a few months. I can
I published my app 2 months ago and sometimes, I am geting some reports
I published an app 2 moths ago and sometimes, I am getting some errors
I published an app to the android market about 3 hours ago and it
I currently have an app published on the App Store but I've just updated
I published my first app to the Android Market an have the weird problem,
I published my first app yesterday evening, and it appears under this url: https://play.google.com/store/apps/details?id=com.appname
I just published my first app and already there are a bunch of mistakes

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.