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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:38:44+00:00 2026-06-13T14:38:44+00:00

I save and read an ArrayList locally on my phone. When I try to

  • 0

I save and read an ArrayList locally on my phone. When I try to open the file there is a NullPointerException. But I cannot find the problem.

The ArrayList are defined globally as private static ArrayList<Datapoint> XML = null; and private static ArrayList<Datapoint> itemsList = null;

The code to save the file:

//save arraylist as file 
            //change path to a non-root folder
            String filePath = context.getFilesDir().getPath().toString() + FileSeperator + Name;
            Log.d("FILESTREAMonFolder", "Filepath:"+filePath+ " Projektname:"+Name);
            File f = new File(filePath);
            try {
                FileOutputStream fileOut = new FileOutputStream(f);
                ObjectOutputStream out = new ObjectOutputStream(fileOut);
                out.writeObject(itemsList);
                out.close();
                fileOut.close();
            } catch(IOException ioe) {
                ioe.printStackTrace();
            }       

The code to read the file:

//read ArrayList which is saved local
//change path to non-root folder
String filePath = context.getFilesDir().getPath().toString()+"/"+Name;
Log.d("FILESTREAMfromFolder", "Filepath:"+filePath+ " Projektname:"+Name);
File f = new File(filePath);
try
{
    FileInputStream fileIn = new FileInputStream(f);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    XML = (ArrayList<Datapoint>) in.readObject();
    Log.d("XML",XML.toString());
    in.close();
    fileIn.close();
} catch(IOException ioe)
{
    ioe.printStackTrace();
    return;
} catch(ClassNotFoundException c)
{
    Log.d("FILESTREAM", ".Datapoint class not found.");
    c.printStackTrace();
    return;
}

The LogCat output:

10-24 17:19:51.210: D/FILESTREAMonFolder(15446): Filepath:/data/data/de.myapp./files/test Projektname:test
10-24 17:19:51.325: D/AbsListView(15446): Get MotionRecognitionManager
10-24 17:19:53.625: D/CREATED_FILE(15446): test.xml
10-24 17:20:04.110: I/System.out(15446): ..Tunneling, NAT ignored, TP1 medium
10-24 17:20:04.110: I/System.out(15446): ..Local  EP:connect:Exception = null
10-24 17:20:04.110: I/System.out(15446): Can not connect to KNX/IP-Router
10-24 17:20:04.140: D/dalvikvm(15446): GC_CONCURRENT freed 382K, 5% free 14931K/15559K, paused 2ms+6ms
10-24 17:20:04.145: D/AbsListView(15446): [unregisterDoubleTapMotionListener]
10-24 17:20:04.145: I/MotionRecognitionManager(15446):   .unregisterListener : / listener count = 0->0, listener=android.widget.AbsListView$4@418fe150
10-24 17:20:04.195: D/AbsListView(15446): Get MotionRecognitionManager
10-24 17:20:04.200: D/FILESTREAMfromFolder(15446): Filepath:/data/data/de.bertrandt.bertrandtknx/files/test Projektname:test
10-24 17:20:04.200: D/AndroidRuntime(15446): Shutting down VM
10-24 17:20:04.200: W/dalvikvm(15446): threadid=1: thread exiting with uncaught exception (group=0x40c5d1f8)
10-24 17:20:04.205: E/AndroidRuntime(15446): FATAL EXCEPTION: main
10-24 17:20:04.205: E/AndroidRuntime(15446): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.myapp./de.myapp.ProjectView}: java.lang.NullPointerException
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread.access$600(ActivityThread.java:128)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.os.Looper.loop(Looper.java:137)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread.main(ActivityThread.java:4514)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at java.lang.reflect.Method.invokeNative(Native Method)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at java.lang.reflect.Method.invoke(Method.java:511)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at dalvik.system.NativeStart.main(Native Method)
10-24 17:20:04.205: E/AndroidRuntime(15446): Caused by: java.lang.NullPointerException
10-24 17:20:04.205: E/AndroidRuntime(15446):    at de.myapp.ProjectView.setup(ProjectView.java:220)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at de.myapp.ProjectView.onCreate(ProjectView.java:85)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.Activity.performCreate(Activity.java:4562)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
10-24 17:20:04.205: E/AndroidRuntime(15446):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
10-24 17:20:04.205: E/AndroidRuntime(15446):    ... 11 more
  • 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-13T14:38:45+00:00Added an answer on June 13, 2026 at 2:38 pm

    I had to put the write code inside the OnPostExecute() method of my AsyncTask for downloading the file and now it works!

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

Sidebar

Related Questions

This question is related to the previous post. How to save file and read
Basically I want to read and write to a file then save all the
I am trying to save a file (and then read it later) in java
is it possible to read mongodb data with hadoop connector but save output as
I always read that I should use model = Model(a=5, b=6) model.save() But I
I want to save a matrix to a text file, so I can read
I need to read a file from the local file system using JSP, save
I would like to save and read an ICO file. It doesnt matter if
Now I have to do some processing(such as read/save) with some .tif images, but
I have a Arraylist, which i want to save in a file for use

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.