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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:47:51+00:00 2026-06-17T15:47:51+00:00

I would love to receive some help from second eyes, for I have struggled

  • 0

I would love to receive some help from second eyes, for I have struggled to identify what is wrong with my code.

In the Eclipse IDE I am attempting to implement a Google Maps activity that reads seaship MMSI codes from a file in the assets folder (/assets/mmsi.txt) and adds maps markers to their respective locations. I am able to read from this file using the BufferedReader class but am having problems in converting the resulting String lines to double using the Double.parseDouble function.

LogCat detects the following problems.

01-23 17:59:11.672: E/AndroidRuntime(18242): FATAL EXCEPTION: main
01-23 17:59:11.672: E/AndroidRuntime(18242): java.lang.RuntimeException: Unable to resume activity {com.aquamet.saramap/com.aquamet.saramap.MainActivity}: java.lang.NullPointerException
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3143)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.os.Looper.loop(Looper.java:123)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.main(ActivityThread.java:4627)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at java.lang.reflect.Method.invokeNative(Native Method)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at java.lang.reflect.Method.invoke(Method.java:521)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at dalvik.system.NativeStart.main(Native Method)
01-23 17:59:11.672: E/AndroidRuntime(18242): Caused by: java.lang.NullPointerException
01-23 17:59:11.672: E/AndroidRuntime(18242):    at com.aquamet.saramap.MainActivity.getMMSI(MainActivity.java:173)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at com.aquamet.saramap.MainActivity.setupRegion(MainActivity.java:136)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at com.aquamet.saramap.MainActivity.onResume(MainActivity.java:82)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.Activity.performResume(Activity.java:3827)
01-23 17:59:11.672: E/AndroidRuntime(18242):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
01-23 17:59:11.672: E/AndroidRuntime(18242):    ... 12 more

In other words, there seems to be a NullPointerException in the following code:

private double[] getMMSI() throws IOException {
        AssetManager am = this.getAssets();
        double[] mmsi = null;
        BufferedReader br = null;

        try {
            InputStream  file_stream = am.open("mmsi.txt");
            br = new BufferedReader(new InputStreamReader(file_stream));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        String line;
        for (int i=0; (line = br.readLine()) != null; i++) {
                // Following line seems to be the problem (line 173).
                mmsi[i] = Double.parseDouble(line);
        }

        try {
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
}

But, while debugging the variable line is infact not null! (Sorry not enough REP for images)
Debugging Screenshot

Another SO user had quite a similar problem, but his variables did seem to be badly initialized.
parseDouble throwing Null Pointer in my code [closed]

  • 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-17T15:47:53+00:00Added an answer on June 17, 2026 at 3:47 pm

    Double.parseDouble isn’t the problem. Your assignment is:

    double[] mmsi = null;
    ...
    // mssi is still null...
    mmsi[i] = Double.parseDouble(line);
    

    You never assign a non-null value to mmsi, hence the error when you try to write into it. If you want further proof of this, split your code into:

    double tmp = Double.parseDouble(line);
    mmsi[i] = tmp;
    

    You’ll see that the exception occurs on the second line, not the first.

    Given that you don’t know how many lines you’ll need, I’d suggest you use an ArrayList instead:

    List<Double> mmsi = new ArrayList<Double>();
    ...
    mmsi.add(Double.valueOf(line));
    

    EDIT: Additionally, you should be closing your file in a finally block. Currently, if an exception is thrown while you’re reading, you leave the file open. And your current catch block implementations aren’t as useful as just letting the exception be thrown, IMO.

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

Sidebar

Related Questions

I would love to get some tips from other people that have had this
I would love some help with a regular expression that tests a string for
I would love to have a plugin or some script that recreates the tool
Would love some help here... Firefox displays the last column in the table (an
Would love some opinions on this problem I'm trying to workout. I'm trying to
I would love to sort an embedded MongoDB object using PHP Lithium. I have
I am in the midst of a short thought experiment and would love some
I am working on generating emails using Java. I would love to use some
Using the following code, assume I have 5 different types that I might receive
I have a java application that I run from eclipse 3.5. My OS is

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.