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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:05:21+00:00 2026-06-17T18:05:21+00:00

In my program, I have an SQLite that stores GPS coordinates for google maps

  • 0

In my program, I have an SQLite that stores GPS coordinates for google maps in my application.
I try to retrieve the latitude and longitude and store them in a arrayList, but the program throws indexOutOfBoundsException when I run the program. I vaguely understand that this means there’s nothing in the arrayList when I try to retrieve a item from it, but please correct me if I’m wrong.

LogCat

01-22 14:39:54.750: E/AndroidRuntime(21639): FATAL EXCEPTION: main
01-22 14:39:54.750: E/AndroidRuntime(21639): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidbasic12/com.example.androidbasic12.map}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.os.Looper.loop(Looper.java:137)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread.main(ActivityThread.java:4511)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at java.lang.reflect.Method.invokeNative(Native Method)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at java.lang.reflect.Method.invoke(Method.java:511)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at dalvik.system.NativeStart.main(Native Method)
01-22 14:39:54.750: E/AndroidRuntime(21639): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-22 14:39:54.750: E/AndroidRuntime(21639):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at java.util.ArrayList.get(ArrayList.java:304)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at com.example.androidbasic12.map.onCreate(map.java:58)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at  android.app.Activity.performCreate(Activity.java:4470)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-22 14:39:54.750: E/AndroidRuntime(21639):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-22 14:39:54.750: E/AndroidRuntime(21639):    ... 11 more

The raw query in class “DatabaseHandler.class”

    public Cursor getLatLng(){
    SQLiteDatabase db = this.getReadableDatabase();
    String query = ("SELECT * FROM " + TABLE_CARCOORD + " WHERE name = " + CAR_KEY_NAME);
    Cursor cursor = db.rawQuery(query, null);
    return cursor;

}

Class “UserFunction.class”

    public ArrayList<String> getCoords(Context context, String lat, String lng) {
    DatabaseHandler db = new DatabaseHandler(context);
    Cursor cursor = db.getLatLng();
    ArrayList<String> cordarr = new ArrayList<String>();
    if (cursor.moveToFirst()){
        lat = cursor.getString(cursor.getColumnIndex("lat"));
        lng = cursor.getString(cursor.getColumnIndex("lng"));
        cordarr.add(lat);
        cordarr.add(lng);
    }
cursor.close();
db.close();
return cordarr;
}

map.class

    UserFunctions userFunc = new UserFunctions();
    ArrayList<String> cordarr = new ArrayList<String>();
    cordarr = userFunc.getCoords(getApplicationContext(), Lat1, Lng1);
    Lat1 = cordarr.get(0);
    Lng1 = cordarr.get(1);
    lat = goDouble(Lat1);
    lng  = goDouble(Lng1);
    LatLng sala = new LatLng(lat, lng);

Function that takes strings and convert to double for use in googlemaps

    public Double goDouble(String Latlng) {
    Double goDouble = Double.parseDouble(Latlng);
    return goDouble;
}
  • 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-17T18:05:23+00:00Added an answer on June 17, 2026 at 6:05 pm

    You should have null check here,

        public ArrayList<String> getCoords(Context context, String lat, String lng) {
            DatabaseHandler db = new DatabaseHandler(context);
            Cursor cursor = db.getLatLng();
            if (cursor !null && cursor.moveToFirst()){
                  ArrayList<String> cordarr = new ArrayList<String>();
                lat = cursor.getString(cursor.getColumnIndex("lat"));
                lng = cursor.getString(cursor.getColumnIndex("lng"));
                cordarr.add(lat);
                cordarr.add(lng);
                return cordarr;
            }
        cursor.close();
        db.close();
        return null;
        }
    

    and here too,

        UserFunctions userFunc = new UserFunctions();
        ArrayList<String> cordarr = new ArrayList<String>();
        cordarr = userFunc.getCoords(getApplicationContext(), Lat1, Lng1);
        if(cordarr != null && cordarr.size() > 1) {
        Log.d("LOG","have got lat long to show.")
        Lat1 = cordarr.get(0);
        Lng1 = cordarr.get(1);
        lat = goDouble(Lat1);
        lng  = goDouble(Lng1);
        LatLng sala = new LatLng(lat, lng); 
        } else {
            Log.d("LOG","no lat long found")
        }
    

    will u try this and let me see what logs u are getting

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

Sidebar

Related Questions

I have a program that needs to retrieve some data about a set of
I have written a simple Android application that uses a sqlite database which is
I'm developing an Android application that stores its data inside the usual SQLite DB.
I have an iOS app that uses a SQLite DB to store its data
I have a budget program that uses multiple tables to store information. When I
I have an SQLite database within my Android application, which stores dates as integers.
I have a single user java program that I would like to have store
I have a sample program that use Core Data and load an sqlite database
I'm developing a simple android application that stores current(now) date into sqlite database. Later
I have written a java application that sporadically logs events to an SQLite database

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.