• 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

Add Strings to 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".

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
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the stack trace and the code showing the lines where the Exception occurred.
 
Kyupa Supa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was told by teacher to use Lists now. Not Array, as I chose, because I'll need not a fixed length
 
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic