aspose file tools*
The moose likes Java in General and the fly likes Add Strings to String Array in Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Add Strings to String Array in Java?" Watch "Add Strings to String Array in Java?" New topic
Author

Add Strings to String Array in Java?

Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
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".

Course.java




Same with Professor.java:


...................

Same with PC.java:



..................

ArrayList<PC> results contains prof_id <-> course_id

ArrayList<Course> courses contains course_id <-> title (identical with the table "courses")

I need these for example because let's say:

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", so cs[] = {"French", "Spanish"}

All in all I want to take only the "title" fields from ArrayList "courses" and store them into a String array (cs[]).

In JSP I would display the titles:


I have Exception at the array:

org.apache.jasper.JasperException: java.lang.NullPointerException
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Please post the stack trace and the code showing the lines where the Exception occurred.
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
Oops... SORRYYY, I modified a line of code AFTER I mentioned the exception here and now I don't have exception anymore, but it displays:

null
null
null

3 times,

instead of:

French
Spanish

They are actually just 2 courses.

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Kyupa Supa wrote:Oops... SORRYYY, I modified a line of code AFTER I mentioned the exception here and now I don't have exception anymore, but it displays:
. . .

What was the original code throwing the Exception? What displays null? Where from? How are you instantiating your objects? What is the input from the database? We can’t help if we don’t know the full details.
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
I was told by teacher to use Lists now. Not Array, as I chose, because I'll need not a fixed length
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Add Strings to String Array in Java?