Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Unit Testing a Spring Application Starter App crashes --- 500 error comes up

Hi

I dowloade the project from Github, per instruction and was able to run it in the IDE after I obtained a secret key from google. Once I typr http://localhost:8080, I get the search page where there is a login option. I login with user / password, and I enter a zip cod in the search box ... 500 error comes up as shown below.

This is in video 2 of the course. I am trying to debug to see where is the offending part ... but I suspect something is out of date?

Please advise of you have run into this issue and how to fix.

Thank you

HTTP Status 500 - Request processing failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

type Exception report

message Request processing failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    java.util.ArrayList.rangeCheck(ArrayList.java:653)
    java.util.ArrayList.get(ArrayList.java:429)
    com.teamtreehouse.service.resttemplate.geocoding.GeocodingServiceImpl.findBySearchTerm(GeocodingServiceImpl.java:38)
    com.teamtreehouse.web.controller.WeatherController.getWeatherForSearchTerm(WeatherController.java:40)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:860)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:96)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.30 logs.

Hi Graig

I did add the API key ... please note that the video says ... see teacher's note for instruction how to get API and so forth, but there is no teacher's note.

But I did get the key and added it to the project api.properties file. I am looking at the https://console.developers.google.com/apis/dashboard. Every time I restart the weather app and put a zip code in the text-box, and hit Enter, I see a crash,. On the google dashboard I see a spike representing the access request.? 4 crashed, I see 4 spikes that I just tried.

I have not made any changes to the GITHUB project other than adding the KEY

I really need to get this course going in prep fro the upcoming TDD.

Thank you for your help

Hi Craig

I re - downloaded the project again from GITHUB .... re-edited the api.properties files. This time I saw the teacher's notes in GITHUB about the installation, which is identical to what I did, but for sanity check ... I re-did the instructions again.

No change ...still crashing.

Is it possible to see if someone else can get this working ? Google does make changes for stuff that are free?

Thanks

Craig Dennis
Craig Dennis
Treehouse Teacher

Did you do this too in Google Console? From the README:

At this point you need to enable the Geocoding and Places API, so that your API key grants you access to those APIs. Under the menu item Overview, you should see a categorized list of Google APIs.

Under the Google Maps category, enable the following APIs:

Google Maps Geocoding API, and
Google Places API Web Service

It's called dashboard now. I downloaded and verified this worked today.

Hi Craig

Regarding your note: "At this point you need to enable the Geocoding and Places API, so that your API key grants you access to those APIs. Under the menu item Overview, you should see a categorized list of Google APIs.

Under the Google Maps category, enable the following APIs:

Google Maps Geocoding API, and Google Places API Web Service

"

Yes they are enabled.

If you look at the Dashboard ... you will see you have to take an action to disable them, other wise, they are enabled. But then again, I went ahead and disabled them and then enabled them back.

Still same results. Crash

If you are saying that you just downloaded the project and it works for you ... I guess I need to give up on this course after couple of days of trying to get it working with no success. The process is pretty simple. Get API, update the apl.properties file. make sure Google Maps Geocoding API, and Google Places API Web Service are enabled in dashboard and that is it. But it is not working.

These are eanbled on my dashboard

API Requests Errors Error ratio Latency, median Latency, 98%
Google Maps Geocoding API 14 0 0% — — Disable BigQuery API — — — — — Disable Google Cloud Datastore API — — — — — Disable Google Cloud SQL — — — — — Disable Google Cloud Storage — — — — — Disable Google Maps JavaScript API — — — — — Disable Google Places API Web Service — — — — — Disable Google Service Management API — — — — — Disable Stackdriver Debugger API — — — — — Disable Stackdriver Logging API — — — — — Disable Stackdriver Monitoring API — — — — — Disable Stackdriver Trace API

I wonder if other folks are giving up because of same issue??? A good test is using an independent tester ... a freshman to check it out. Your test may be biased if you had an older key??? I am not sure ... just puzzled.

Thank you for your help.

3 Answers

Pooh ... Third try is a charm

Craig, Seth ... thanks for the help. I appreciate it. I got it working with a third start from scratch re-setup.

Seth Kroger
Seth Kroger
56,413 Points

There is a break about half-way down that shows you where in the project code the exception happened. I suspect the query to the geocode API is coming up empty, but the code doesn't check for it before pulling out a result.

Hi

I saw that ... but the code is a direct clone from github ... and the zip codes I am putting are valid zip codes.

I am currently stuck in video 2 .. can't follow along with the nstructor.

Thanks

Craig Dennis
Craig Dennis
Treehouse Teacher

Hi Mark!

Did you add the API keys and enable the Geocoding and Google Places APIs in the Google Console dashboard? My guess is, like Seth suggested that you are getting a Request Denied response from Google.

Let me know if you've done this...I see this error when the APIs aren't configured correctly.

Robert Goddard
Robert Goddard
15,019 Points

There's a new problem some folks may run into. forecast.io is now darksky.net so change:

weather.api.name = forecast.io API
weather.api.key = [your api key here]
weather.api.host = api.forecast.io

to

weather.api.name = darksky.net API
weather.api.key = [your api key here]
weather.api.host = api.darksky.net
Sylwester Guzek
Sylwester Guzek
16,088 Points

I had the same problem due to the fact that I put API key in quotes. Why quotes are not needed for Strings in api.properties file ?