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

  • Home
  • SEARCH
  • 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 9147969
In Process

The Archive Base Latest Questions

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

program not error but logcat error about index array list so picture I can’t

  • 0

program not error but logcat error about index array list so picture I can’t solve . please help me.

public class MainActivity extends MapActivity {

@Override

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    MapView mv = (MapView) findViewById(R.id.mapview);

    mv.setBuiltInZoomControls(true);

    MapController mc = mv.getController();

    ArrayList all_geo_points = getDirections(16.821219, 100.260457, 13.913698, 100.510954);

    GeoPoint moveTo = (GeoPoint) all_geo_points.get(0);

    mc.animateTo(moveTo);

    mc.setZoom(12);

    mv.getOverlays().add(new MyOverlay(all_geo_points));

}


@Override

protected boolean isRouteDisplayed() {


    return false;

}



public static ArrayList getDirections(double lat1, double lon1, double lat2, double lon2) {

    String url = "http://maps.googleapis.com/maps/api/directions/xml?origin=" +lat1 + "," + lon1  + "&destination=" + lat2 + "," + lon2 + "&sensor=false&units=metric";

    String tag[] = { "lat", "lng" };

    ArrayList list_of_geopoints = new ArrayList();

    HttpResponse response = null;

    try {

        HttpClient httpClient = new DefaultHttpClient();

        HttpContext localContext = new BasicHttpContext();

        HttpPost httpPost = new HttpPost(url);

        response = httpClient.execute(httpPost, localContext);

        InputStream in = response.getEntity().getContent();

        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();

        Document doc = builder.parse(in);

        if (doc != null) {

            NodeList nl1, nl2;

            nl1 = doc.getElementsByTagName(tag[0]);
            nl2 = doc.getElementsByTagName(tag[1]);

            if (nl1.getLength() > 0) {

                list_of_geopoints = new ArrayList();

                for (int i = 0; i < nl1.getLength(); i++) {

                    Node node1 = nl1.item(i);

                    Node node2 = nl2.item(i);

                    double lat = Double.parseDouble(node1.getTextContent());

                    double lng = Double.parseDouble(node2.getTextContent());

                    list_of_geopoints.add(new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)));

                }

            } else {
                // No points found
            }

        }

    } catch (Exception e) {

        e.printStackTrace();

    }

    return list_of_geopoints;

}

public class MyOverlay extends Overlay {


    private ArrayList all_geo_points;

    public MyOverlay(ArrayList allGeoPoints) {

        super();

      this.all_geo_points = allGeoPoints;

    }


    @Override

    public boolean draw(Canvas canvas, MapView mv, boolean shadow, long when) {

        super.draw(canvas, mv, shadow);

        drawPath(mv, canvas);

        return true;

    }

    public void drawPath(MapView mv, Canvas canvas) {

        int xPrev = -1, yPrev = -1, xNow = -1, yNow = -1;

        Paint paint = new Paint();

        paint.setColor(Color.BLUE);

        paint.setStyle(Paint.Style.FILL_AND_STROKE);

        paint.setStrokeWidth(4);

    paint.setAlpha(100);

        if (all_geo_points != null)

            for (int i = 0; i < all_geo_points.size() - 4; i++) {

                GeoPoint gp = (GeoPoint) all_geo_points.get(i);

                Point point = new Point();

                mv.getProjection().toPixels(gp, point);

                xNow = point.x;

                yNow = point.y;

                if (xPrev != -1) {

                    canvas.drawLine(xPrev, yPrev, xNow, yNow, paint);

               }

                xPrev = xNow;

                yPrev = yNow;

            }

    }

}

}

This is code About google maps is line drive so input point latitude and longtitude two point for way line to driver and input is array . In code don’t error but code have warning about array 8 wraning it all warning about array. run program have error logcat about array index.


01-18 00:37:29.720: E/AndroidRuntime(667): FATAL EXCEPTION: main
01-18 00:37:29.720: E/AndroidRuntime(667): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.getgoogledirection/com.example.getgoogledirection.MainActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.os.Looper.loop(Looper.java:137)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.lang.reflect.Method.invoke(Method.java:511)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-18 00:37:29.720: E/AndroidRuntime(667): at dalvik.system.NativeStart.main(Native Method)
01-18 00:37:29.720: E/AndroidRuntime(667): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
01-18 00:37:29.720: E/AndroidRuntime(667): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-18 00:37:29.720: E/AndroidRuntime(667): at java.util.ArrayList.get(ArrayList.java:304)
01-18 00:37:29.720: E/AndroidRuntime(667): at com.example.getgoogledirection.MainActivity.onCreate(MainActivity.java:45)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.Activity.performCreate(Activity.java:5008)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
01-18 00:37:29.720: E/AndroidRuntime(667): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

  • 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-17T11:08:20+00:00Added an answer on June 17, 2026 at 11:08 am

    It would be much easier to help you, if you put the output of logcat here.
    As you mention, the error probably comes from the method getDirections.

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

Sidebar

Related Questions

I can't understand why my program not functioning. It compiles but nothing is printed.
My program compiles fine, but crashes everytime throw (not inside of a try...catch block)
I write this code in Main.java class but the program not run. Why? the
i need to hide a windows program (not visible in taskbar, system tray. visible
I would like to add a QMenuBar to a window of my program (not
Why the following program is not printing garbage values . As i know ,
I am wondering why my C program does not print any information. I am
When answering another question, I realized that the following program does not quite do
In the below program,i am not getting values from printf . #include<stdio.h> int main()
Edit (updated question) I have a simple C program: // it is not important

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.