Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Maps android API, drawing polylines in a loop
    primarykey
    data
    text
    <p>I have two String arrays, <code>latitude</code> and <code>longitude</code> I want to draw polylines on the map, the <a href="https://developers.google.com/maps/documentation/android/lines#add_a_polyline" rel="nofollow">documentation</a> says, that it's as easy as pie. And it is. If I add polylines manually like this, it works:</p> <pre><code>PolylineOptions rectOptions = new PolylineOptions() .add(new LatLng(37.35, -122.0)) .add(new LatLng(37.45, -122.0)) .add(new LatLng(37.45, -122.2)) </code></pre> <p>But the problem starts when I'm trying to loop adding polylines:</p> <pre><code> rectOptions = new PolylineOptions(); for(int i = 0; i&lt;latitude.length(); i++){ rectOptions.add(new LatLng(Long.getLong(latitude[i]), Long.getLong(longitude[i]))); // Log.d("coordinates", latitude[i]+"|"+longitude[i]); } </code></pre> <p>I get a <code>java.lang.NullPointerException</code> And I don't know why. I know the problem is in the <code>rectOptions.add()</code> method, because <code>Log.d("coordinates", latitude[i]+"|"+longitude[i]);</code> works fine in the same loop.</p> <p>Here's the output of LogCat:</p> <pre><code> 01-02 11:59:27.380: E/AndroidRuntime(25146): FATAL EXCEPTION: main 01-02 11:59:27.380: E/AndroidRuntime(25146): java.lang.NullPointerException 01-02 11:59:27.380: E/AndroidRuntime(25146): at com.shniv.MainActivity$1.onClick(MainActivity.java:82) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.view.View.performClick(View.java:3519) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.view.View$PerformClick.run(View.java:14140) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Handler.handleCallback(Handler.java:605) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Handler.dispatchMessage(Handler.java:92) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.os.Looper.loop(Looper.java:137) 01-02 11:59:27.380: E/AndroidRuntime(25146): at android.app.ActivityThread.main(ActivityThread.java:4456) 01-02 11:59:27.380: E/AndroidRuntime(25146): at java.lang.reflect.Method.invokeNative(Native Method) 01-02 11:59:27.380: E/AndroidRuntime(25146): at java.lang.reflect.Method.invoke(Method.java:511) 01-02 11:59:27.380: E/AndroidRuntime(25146): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787) 01-02 11:59:27.380: E/AndroidRuntime(25146): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) 01-02 11:59:27.380: E/AndroidRuntime(25146): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload