Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception String array in Java?  RSS feed

Kyupa Supa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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 ** 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


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


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!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!