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

  • Home
  • SEARCH
  • 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 6585953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:43:44+00:00 2026-05-25T16:43:44+00:00

I have a little problem with writing a file in internal storage from my

  • 0

I have a little problem with writing a file in internal storage from my application.I’m gettin a null pointer exception,but can’t find the way to fix it..and actually can’t understand which one of the elements is null.

Here is the code that I’m using :

hash= jsonObj.getString("hash");
Log.w("CLIENT AUTH HASH","SHOW CLIENT AUTH HASH : "+hash);                  
FileOutputStream out = context.openFileOutput("autohash",context.MODE_PRIVATE);
out.write(hash.getBytes());
out.close();

The class where I’m trying to create and write this file is not an Activity, it’s just some kind of helper class and that’s why it’s giving me error when I try to set context=this;.
And actually the NullPointerException it thrown at this line : FileOutputStream out = context.openFileOutput("autohash",context.MODE_PRIVATE);, and I can’t get it, which cause this exception :

  1. The Context

or

  1. autohash – file (exist or don’t).

Second scenario :

I have the same function of saving the file in internal storage,but I’m calling that method from another activity.Here is the situation:

I have different packets received over the internet and I’m doing something like this :

BasePacket packet; //all other packets extends this class.
byte[] buffer=byte[1024];
//packet calculations
switch(packetType){
  case startPacket:
    packet = new startPacket(/*params*/);
    packet.startExecutePacket();
 case endPacket:
    //same procedure
}

and in startExecutePacket() I’m trying to save the file.

So any kind of help are welcomed!Thanks in advance!

  • 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-05-25T16:43:45+00:00Added an answer on May 25, 2026 at 4:43 pm

    CallingActivity.java

    onCreate()
    
    helperClass mHelper= new helperClass(CallingActivity.this);
    

    helperClass.java

    //declare a context
    context refContext;
    
    //constructor
    public helperClass(context mContext)
    {
       refContext=mContext;
    }
    
    //and you code
    
        hash= jsonObj.getString("hash");
        Log.w("CLIENT AUTH HASH","SHOW CLIENT AUTH HASH : "+hash);                  
        FileOutputStream out = refContext.openFileOutput("autohash",Context.MODE_PRIVATE);
        out.write(hash.getBytes());
        out.close();
    

    try with this one

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

Sidebar

Related Questions

I am writing some documentation and I have a little vocabulary problem: http://www.example.com/en/public/img/logo.gif is
I'm writing a little Java program (it's an ImageJ plugin, but the problem is
I'm writing a simple ini file parser and I'm having a little problem with
I am writing a little gui application with Tkinter, which requires me to have
I'm writing a custom ATL ActiveX component, but I'm having this little weeny problem:
I am writing a little test program, and I have a problem regarding the
I have little problem with a replacement of a little part in an url.
I have little problem in regular expressin creation. Expected input: blahblahblah, blahblahblah, 'blahblahblah', blahblahblah,
I have a little problem with a simple vbScript. The script has to run
I have a little problem with some jquery and http://www.mikage.to/jquery/jquery_history_noc.html The function works 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.