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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:04:08+00:00 2026-06-17T06:04:08+00:00

I am coding an application for android which is supposed to get coordinates from

  • 0

I am coding an application for android which is supposed to get coordinates from a JSON document, convert this Strings to double and then use this doubles to create overlays on google map.

But i get an exception called NumberFormatException.

    public class LagerActivity extends Activity {

private static String url = "http://agent.nocrew.org/api/json/1.0/searchStore.json?limit=500";

static final String TAG_ITEMS = "items";
static final String TAG_LAT = "lat";
static final String TAG_LNG = "lng";

private GoogleMap mMap;
private LocationManager locationManager;

JSONArray items = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lager);
    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
            .getMap();

    // Creating JSON Parser instance
    JSONparser jParser = new JSONparser();
    // getting JSON string from URL
    JSONObject json = jParser.getJSONFromUrl(url);

    try {
        // Getting Array of Contacts
        items = json.getJSONArray(TAG_ITEMS);
        // looping through All Contacts
        for (int i = 0; i < items.length(); i++) {
            JSONObject c = items.getJSONObject(i);

            // Storing each json item in variable
            String lat = c.getString(TAG_LAT);
            String lng = c.getString(TAG_LNG);

            // lat = lat.replace(",", ".");
            // lng = lng.replace(",", ".");

            // Log.e(lat, lng);

            double lati = Double.parseDouble(lat);

            Log.d(Double.toString(lati), " ");

            // LatLng point = new LatLng(Double.parseDouble(lat),
            // Double.parseDouble(lng));
                // mMap.addMarker(new MarkerOptions().position(point)
            // .title("Karls räkor & hund")
            // .snippet("blaha, ehehe"));

        }

    } catch (JSONException e) {
        e.printStackTrace();
    }

}

    }

Here is my logcat:

    01-11 18:10:23.294: W/dalvikvm(22718): threadid=1: thread exiting with uncaught         exception (group=0x40e86930)
    01-11 18:10:23.294: E/AndroidRuntime(22718): FATAL EXCEPTION: main
    01-11 18:10:23.294: E/AndroidRuntime(22718): java.lang.RuntimeException: Unable to  start activity               ComponentInfo{com.example.checkmypint/com.example.checkmypint.LagerActivity}:    java.lang.NumberFormatException: Invalid double: ""
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at         android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at  android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at   android.app.ActivityThread.access$600(ActivityThread.java:141)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at  android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.os.Handler.dispatchMessage(Handler.java:99)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.os.Looper.loop(Looper.java:137)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.app.ActivityThread.main(ActivityThread.java:5039)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at java.lang.reflect.Method.invokeNative(Native Method)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at java.lang.reflect.Method.invoke(Method.java:511)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at dalvik.system.NativeStart.main(Native Method)
    01-11 18:10:23.294: E/AndroidRuntime(22718): Caused by: java.lang.NumberFormatException: Invalid double: ""
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at java.lang.StringToReal.invalidReal(StringToReal.java:63)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at java.lang.StringToReal.parseDouble(StringToReal.java:248)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at java.lang.Double.parseDouble(Double.java:295)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at com.example.checkmypint.LagerActivity.onCreate(LagerActivity.java:65)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.app.Activity.performCreate(Activity.java:5104)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    01-11 18:10:23.294: E/AndroidRuntime(22718):    ... 11 more

Annyone got anny ideas? The logcat tells me i have the data from JSON.

  • 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-17T06:04:09+00:00Added an answer on June 17, 2026 at 6:04 am

    The exception is telling you exactly what’s wrong:

    NumberFormatException: Invalid double: ""

    You’re trying to use Double.parseDouble on the string "". That fails. You need to check for the "" case:

    String lat = c.getString(TAG_LAT);
    double lati;
    
    if (lat == null || lat.length == 0) {
        lati = /* use whatever default you want to use here */;
    }
    else {
        double lati = Double.parseDouble(lat);
    }
    

    …and similarly for lng, presumably.

    You’ll want to catch and handle the exception anyway at some level (in case the incoming JSON is truly invalid, lat: "foo" or similar), but since apparently the input data sometimes has blank lat or lng, that’s no longer an exceptional case, and so you can handle it inline using if.

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

Sidebar

Related Questions

I'm coding a simple android application which contains a list, populated with a SimpleCursorAdapter.
Im just coding the Android application which I thought of in order to learn
I wanted to develop an Android application which allows users to transfer files from
So I'm making this android application, that needs to read data from user-provided CSV
I am developing an android application in which i have data coming from Url,The
I have an application which pulls data from a webserver, putting this data in
I am quite new to Java and am currently coding an Android application. In
I am currently coding an application then decided to add HoloEverywhere into my application.
assume that i start coding an application from scratch, is the best way to
I'm coding an MFC application in which i have a dialog box with multiple

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.