• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception String array in Java?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 3 sql tables: **professors(prof_id, name)**, **professors_courses(prof_id, course_id)** and **courses(course_id, title)**.

**professors_courses** is the bridge table between professors and courses.

In *CourseAssignments.java* I search which courses belong to professor x, after user enters a professor "name".





Method returns the course titles in a String array, that belong to professor x. I have problems with the array only.

For example:

In "professors" table we have prof_id: 5, name: John;
In professors_courses we have prof_id: 5, course_id: 1
prof_id: 5, course_id: 9
In "courses" table we have course_id: 1, title: French
course_id: 9, title: Spanish
User enters: "John"

In ArrayList "results" I store:
prof_id: 5, course_id: 1 and prof_id: 5, course_id: 9
So it's similar with the bridge table, but only contains the info regarding "John".

In String cs[] I want to store all the courses of John

In JSP:



titles[] should store all the courses so I can display them in a table, but I got exception:


org.apache.jasper.JasperException: An exception occurred processing JSP page /ComplexSearch/FoundS.jsp at line 8


Stacktrace:
.....................

root cause

java.lang.ArrayIndexOutOfBoundsException: 3


I call the method for "John" only just for testing. I'm not sure yet how I will request the name from user. I'm trying to make user choose the name by clicking on the name inside a html table.

Thank you very much!
reply
    Bookmark Topic Watch Topic
  • New Topic