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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:47:50+00:00 2026-05-23T18:47:50+00:00

* INITIALIZE VARIABLES String serfilename; List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>(); ON CREATE

  • 0

*INITIALIZE VARIABLES

String serfilename;

List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();

ON CREATE METHOD

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.addscreen);
//getPainItems from the saved file
if(loadListFromFile((ArrayList<HashMap<String, String>>) painItems) != 
      null)
    painItems = loadListFromFile((ArrayList<HashMap<String, String>>) 
        painItems);
}

LOAD LIST FROM FILE METHOD

private ArrayList<HashMap<String, String>> loadListFromFile(

    ArrayList<HashMap<String, String>> masterlistrev) {
try {

    FileInputStream fis = openFileInput(serfilename);
    ObjectInputStream ois = new ObjectInputStream(fis);
    masterlistrev = (ArrayList<HashMap<String, String>>) ois.readObject();
 } catch (Exception e) {
    e.printStackTrace();
 }
return masterlistrev;
}

WRITE LIST TO FILE METHOD

private void writeListToFile(ArrayList<HashMap<String, String>> masterlistrev){

    File myfile = getFileStreamPath(serfilename);
    try {
        if(myfile.exists() || myfile.createNewFile()){
            FileOutputStream fos = openFileOutput(serfilename, MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(masterlistrev);
     }
 } catch (Exception e) {
     e.printStackTrace();
 }

 }

ONSTOP() METHOD

 protected void onStop(){
    super.onStop();
    writeListToFile((ArrayList<HashMap<String, String>>) painItems);
}

I am getting a NULL Pointer exception at File myfile = getFileStreamPath(serfilename);. How do I fix this.. is there a better way to do this…?

  • 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-23T18:47:51+00:00Added an answer on May 23, 2026 at 6:47 pm

    Based on what you have pasted, your serfilename is null and is never set to a path.

    That said, even without all that,

    File myfile = getFileStreamPath(serfilename);
    

    would be expected to throw a NullPointerException due to your (null) input.

    Convince yourself. Try:

    if(null == serfilename)
        throw new RuntimeException ("serfilename is null!");
    
    File myfile = getFileStreamPath(serfilename);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it better to initialize class member variables on declaration private List<Thing> _things =
I have a list string tag. I am trying to initialize a dictionary with
public class test { public static void main(String[] args) { int MAX = 5;
Let's say I have a class Foo with some primitive instance variables. I initialize
When we create a variable and don't initialize it, then some (random) number called
Consider this: public class TestClass { private String a; private String b; public TestClass()
Is it a good practice to initialize variables, specially object references at class level?
Is it possible to initialize BPEL variables at the declaration ? if so how
I'm trying import CSV file to Arraylist using StringTokenizer : public class Test {
In C++ you can initialize a variable in an if statement, like so: if

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.